Game Development Community


#1
02/02/2007 (1:09 pm)
Not as far as I know.

TGEPython was a solution that Josh Ritter implemented with TGE. He has a more robust and stress-tested solution that he is using with Minions of Mirth, but I'm not sure about the particulars. I would assume that it will be a strong part of the Prairie technology licensing down the road.
#2
02/02/2007 (1:14 pm)
TGEPython is actually a bit on the ancient side. Here is a link to a thread in the TGE forum with a newer binding: PyTGE (also PyTSE) - Python Bindings

Here's the body of the thread's start if you lack access to that forum. The binding does work with TGB, btw :)

-------------

I've had a number of requests for this so here it is sooner rather than later... Python bindings for TGE/TSE and probably TGB:

http://www.prairiegames.com/pytse10a.zip

It's called PyTSE, though there isn't any TSE specific source in it. So, it should build with no modifications with TGE 1.4

This hasn't been field tested, though it should be more or less bug free. Here's the text from the readme.txt, it's sparse I know. Time is a very limited commodity :|

Quote:This is a new TGE/TSE (and probably TGB) Python binding I have been working on. You can do with it what you like.

I don't have any time to document it. Though, the source file is only 16k, so it should be pretty clear.

I've also included a diff of source changes. They should be pretty close to the current HEAD revision.

You need to change your build target to a shared library (a dll on windows, also change to multithreaded dll code generation for this platform)

Here are some minimal docs in the forum of example usage, replace TSE with TGE if that is your desire:

[b]#--- TSE Python Module Example ---[/b]

[b]#TSE as a standard Python extension (no longer a executable)[/b]
import pytse

[b]#initialize pytse, this also executes main.cs and the .cs packages[/b]
pytse.initialize()

[b]#example of executing a script file[/b]
f = file("myscript.cs","rb")
script = f.read()
f.close()
pytse.evaluate(script)

[b]#or, just generate the cs code right inside Python![/b] 
pytse.evaluate("""
new GuiBitmapButtonCtrl(MyButton) {
 profile = "GuiButtonProfile";
 horizSizing = "right";
 vertSizing = "bottom";
 position = "404 361";
 extent = "285 85";
 minExtent = "8 2";
 visible = "1";
 text = "Button";
 groupNum = "-1";
 buttonType = "PushButton";
 bitmap = "./button";
 helpTag = "0";
};""")

[b]#it's easy to grab a reference to the button we created[/b]
button = TSEObject("MyButton")

[b]#buttons are kind of worthless without commands.  Let's make one:[/b]
def OnMyButton(value):
    print "Button pushed with value",value
    
[b]#export the function to the console system in much the same way the C++ system does...
#we also support optional namespaces, usage documentation, and min/max args[/b]
pytse.export(OnMyButton,"MyButton","OnButton","Example button command",1,1)

[b]#we can get and set fields (including dynamic fields).  We'll set our button's command:[/b]
button.command = "MyButton::OnButton(42);"

[b]#we can call console methods on our TSEObjects... So, let's simulate a button click.  
#the OnMyButton function will be called with the value 42 :)[/b]
button.performClick()

[i]#note that getting an object reference to the button and setting the command like this is 
purely for illustration. You can also: command = "MyButton::OnButton(42);" in the evaluated code.[/i]

[b]#moving on, we can get and set global variables[/b]
pytse.setglobal("$MyVariable",42)
print pytse.getglobal("$MyVariable")
pytse.evaluate('echo ("*** Here is your variable:" @ $MyVariable);')

[b]#the main loop is broken out and can be combined with other frameworks rather easily[/b]
while pytse.tick():
    pass

[b]#cleanup pytse.. goodbye![/b]
pytse.shutdown()

Prairie Games, Inc
#3
02/02/2007 (1:18 pm)
I thought you had updated it, but TGEPython was what kept coming up in the search!

Thanks!
#4
02/02/2007 (1:24 pm)
This is great, thanks!

Do you have any idea how fast this is compared to TorqueScript?

I love the ability to use Python instead of TorqueScript but don't want to sacrifice speed or capability. (eg. is PyTSE is missing commands that are available in TorqueScript)
#5
02/03/2007 (8:48 am)
Quick question...

I'm supposed to add pytse.cpp to my existing T2D source project, right? If so, after I add it what do you mean by:

"You need to change your build target to a shared library (a dll on windows, also change to multithreaded dll code generation for this platform)"

Do you have any idea where this option is in Visual Studio 2005? (VC++ Express)

Also, I don't understand why a dll needs to be created. T2D produces an EXE... and it sounds like you're saying to change it to a DLL.

Thanks for your help!
#6
02/05/2007 (5:19 am)
It looks like he's using the Python interpreter's .exe file to launch and drive the Torque engine, rather than using Torque to call out to Python (as it does for TorqueScript). So, Torque needs to be a library rather than an executable.
#7
02/05/2007 (8:13 am)
It's funny that this thread came up, I had just been thinking recently about dropping TorqueScript in favor of Python. The only thing I wouldn't be sure about Python supporting very well would be tagged strings -- but other than that, Python sounds like a very good option for making Torque more usable.

Edit: Okay, sorry -- I just read things in a little more detail, and it doesn't look like this system gets around having to continue to write in Torque Script. I was imagining dropping TorqueScript entirely and just calling Torque console functions directly from Python. There may just be too many issues to deal with for that though, and that might not be very realistic to think about doing.