2021-10-18, 20:36 | #1 |
Join Date: Oct 2021
Posts: 1
Germany
|
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 '__init__.py' and 'helloworld.py' into it, then edited the 'gpm_coop.py' 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 __init__.py Code:
import helloworld def init(): helloworld.init() def deinit(): helloworld.deinit() Code:
import host import bf2 from bf2 import g_debug def init(): host.registerGameStatusHandler(gameStatusChanged) global g_debug g_debug = 1 if g_debug: print "helloworld.py initialized" def deinit(): host.unregisterGameStatusHandler(gameStatusChanged) print "testrotz.py deinitialized" def gameStatusChanged(status): if status == bf2.GameStatus.Playing: host.rcon_invoke("echo HelloWorld") '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. |
2021-10-19, 07:46 | #2 |
PR:BF2 Developer
Join Date: Aug 2009
Posts: 2,988
Israel
|
Re: Starting A Python Script?
For printing and debugging, there's some code in ROOT/python/__init__.py 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. Code:
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. |
Tags |
modding, python |
|
|