Difference between revisions of "HowTo:Edit Missions:Python:Bindings"
Line 41: | Line 41: | ||
Many of these functions return Unit * (for python just Unit) However there is a very critical difference between a Python Unit and a C++ Unit *. If you have a Python Unit you may keep it across frames... it may turn null (check with isNull()), but you can still keep it.... (if it dies is when it turns null)... in C++ if you keep a Unit * across a frame you WILL cause random segfaults (bad things, hard to find) but ya...Python it's safe to keep Unit's returned by functions...just be aware that between frames they may die and then bet tested '''Null''' with '''isNull()'''. | Many of these functions return Unit * (for python just Unit) However there is a very critical difference between a Python Unit and a C++ Unit *. If you have a Python Unit you may keep it across frames... it may turn null (check with isNull()), but you can still keep it.... (if it dies is when it turns null)... in C++ if you keep a Unit * across a frame you WILL cause random segfaults (bad things, hard to find) but ya...Python it's safe to keep Unit's returned by functions...just be aware that between frames they may die and then bet tested '''Null''' with '''isNull()'''. | ||
− | The following comments are done with the python class as the arguments are clearly listed in '''modules/stub/VS.py''' function :-) | + | The following comments are done with the python class as the arguments are clearly listed in '''modules/stub/VS.py''' function :-) ''Add link to CVS'' |
---- | ---- |
Revision as of 06:34, 21 March 2005
HowTo:Edit_Missions:Python:Missions | HowTo:Edit_Missions | HowTo:Edit_Missions:Python:Bindings |
Vegastrike Utility Functions
Now that you can run complex python scripts that could even play minesweeper at the prompt, you probably want to interact with Vegastrike directly and "do" stuff like make ships, set objectives, and generally give the player a hard time.
First of all let me talk about the "stubs". We have had a clever idea to make missions somewhat testable outside the framework of vegastrike by autogenerating stub functions. The way you make stub functions is by using the C++ processor in 2 steps...
cd src/python gcc -E -DPYTHON_STUB=1 unit_wrapper.cpp > /data/modules/stub/VS.py
then edit that file and replace with (newline)(space)(space) and you have a sample python stub so you can find out every mission that vegastrike exports.
we try to keep these stubs as up to date as possible. Anyhow this lets you test your missions at the prompt by adding the two directories
import sys sys.path = sys.path + ['/home/blah/data/modules'] sys.path = sys.path + ['/home/blah/data/modules/stub'] import VS ...
and then you can run your mission and see if it at least sort of works.
the stub file also gives you a good idea about what functions are available for you in your missions.
I will try to give a brief description here...
VegaStrike C++ Funcions
Feel free to add to the descritptions or to ask me about any that are unclear. I give you as follows the VS functions C++ names so you get type information as well! Note that these comments are also included in src/universe_util.h Add link to CVS!
VegaStrike Python Funcions
Many of these functions return Unit * (for python just Unit) However there is a very critical difference between a Python Unit and a C++ Unit *. If you have a Python Unit you may keep it across frames... it may turn null (check with isNull()), but you can still keep it.... (if it dies is when it turns null)... in C++ if you keep a Unit * across a frame you WILL cause random segfaults (bad things, hard to find) but ya...Python it's safe to keep Unit's returned by functions...just be aware that between frames they may die and then bet tested Null with isNull().
The following comments are done with the python class as the arguments are clearly listed in modules/stub/VS.py function :-) Add link to CVS
HowTo:Edit_Missions:Python:Missions | HowTo:Edit_Missions | HowTo:Edit_Missions:Python:Bindings |