project reality header
Go Back   Project Reality Forums > PR:BF2 Mod Forums > PR:BF2 Community Factions > Coding
18 Apr 2024, 00:00:00 (PRT)

Thread Tools Display Modes
Old 2021-10-18, 20:36   #1
Question Starting A Python Script?

Greetings, not sure if its the right place to ask since this is for 'vanilla' bf2 and not PR,
but I really don't know where to ask else and Im trying get a 'Hello World' python script done.

First I created a folder inside the mods/bf2mod/python/game/gamemodes/helloworld
threw '' and '' into it,
then edited the '' in the parent folder 'gamemodes'
added 2 lines to it, 'import helloworld' under line 'from bf2 import g_debug'
and 'helloworld.init()' at the top in the 'def init()' function
import helloworld

def init():
def deinit():
import host
import bf2
from bf2 import g_debug

def init():
	global g_debug
	g_debug = 1
	if g_debug: 
		print " initialized"

def deinit():
	print " deinitialized"
def gameStatusChanged(status):
	if status == bf2.GameStatus.Playing:
		host.rcon_invoke("echo HelloWorld")
Now if I start a game nothing, in the console will show up, first I thought it was a
'rcon' error since I wasnt logged in as an admin but that wasn't the case,
I suspect my script wont even load since my game wont crash on load if
I place a wrong Tabulator in the script for example.

What did I missed? Thanks in advance.
defaultUser is offline Reply With Quote
Old 2021-10-19, 07:46   #2
PR:BF2 Developer
Supporting Member
PR Server License Administrator
Default Re: Starting A Python Script?

For printing and debugging, there's some code in ROOT/python/ that redirects all stdout, so if you haven't disabled that print wont work. Regardless, echo always works unless you have unprintable characters in text.

We use it like this to work with spaces.
host.rcon_invoke('echo "%s"' % text)

I recommend using the dedicated server to test. It launches much faster. Then you can quickly figure out what gets run and what doesn't.
AlonTavor is offline Reply With Quote

modding, python
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

All times are GMT. The time now is 02:22.