Difference between revisions of "HowTo:Edit Missions:Python:Bindings"

From VsWiki
Jump to: navigation, search
 
m
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{NAV_Manual |
 
| previous=[[HowTo:Edit_Missions:Python:Missions]]
 
| up=[[HowTo:Edit_Missions]]
 
| next=[[HowTo:Edit_Missions:Python:Bindings]]
 
}}
 
----
 
 
 
 
==Vegastrike Utility Functions==
 
==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.
 
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.
Line 16: Line 8:
 
</pre>
 
</pre>
  
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.
+
... 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
+
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
  
 
<pre>
 
<pre>
import sys
+
import sys
sys.path = sys.path + ['/home/blah/data/modules']
+
sys.path = sys.path + ['/home/blah/data/modules']
sys.path = sys.path + ['/home/blah/data/modules/stub']
+
sys.path = sys.path + ['/home/blah/data/modules/stub']
import VS
+
import VS
...
+
...
 
</pre>
 
</pre>
  
Line 34: Line 26:
 
I will try to give a brief description here...
 
I will try to give a brief description here...
  
===[[HowTo:Edit_Missions:Python:Bindings:C++|VegaStrike C++ Funcions]]===
+
===[[HowTo:Edit_Missions:Python:Bindings:CPP|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'''
+
 
 +
Feel free to add to the descriptions 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 '''[http://vegastrike.svn.sourceforge.net/viewvc/vegastrike/trunk/vegastrike/src/universe_util.h?view=markup src/universe_util.h]'''
  
 
===[[HowTo:Edit_Missions:Python:Bindings:Python|VegaStrike Python Funcions]]===
 
===[[HowTo:Edit_Missions:Python:Bindings:Python|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()'''.
+
Many of these functions return <code>Unit *</code> (for python just Unit) However there is a very critical difference between a Python <code>Unit</code> and a C++ <code>Unit *</code>. If you have a Python <code>Unit</code> you may keep it across frames... it may turn null (check with <code>isNull()</code>), but you can still keep it.... (if it dies is when it turns null)... in C++ if you keep a <code>Unit *</code> across a frame you WILL cause random segfaults (bad things, hard to find) but ya...Python it's safe to keep <code>Unit</code>'s returned by functions...just be aware that between frames they may die and then bet tested <code>Null</code> with <code>isNull()</code>.
 +
 
 +
The following comments are done with the python class as the arguments are clearly listed in '''[http://vegastrike.svn.sourceforge.net/viewvc/vegastrike/trunk/data4.x/modules/stub/VS.py?view=markup 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 :-)
 
  
----
+
[[Category:HowTos|Edit Missions:Python:Bindings]]
{{NAV_Manual |
+
[[Category:Development|Edit Missions:Python:Bindings]]
| previous=[[HowTo:Edit_Missions:Python:Missions]]
 
| up=[[HowTo:Edit_Missions]]
 
| next=[[HowTo:Edit_Missions:Python:Bindings]]
 
}}
 

Latest revision as of 11:28, 22 April 2008

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 descriptions 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

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 :-)