PyTorque
Description
Python Bindings for Torque Game Engine and Torque Game Engine Advanced
Requirements
Torque Game Engine 1.5 or later
Download the FREE DEMO
Torque Game Engine Advanced 1.02 or later
Torque Game Engine Advanced support will be up soon after TGEA 1.02 is released
Visual Studio 2003 or 2005
OSX support coming soon
Downloads
Source Code and Binary: http://www.mmoworkshop.com/freestuff/pytorque.zip
Torque 1.5 - Quick Installation
1. Install Python25 from http://python.org/ftp/python/2.5/python-2.5.msi
2. Download and install the free demo of the Torque Game Engine
3. Copy the contents of the tge15\example folder in the zip into your TGE 1.5 example folder
4. Double click TorqueDemo.py
Torque 1.5 - Rebuilding from Source
1. Install Python25 from http://python.org/ftp/python/2.5/python-2.5.msi
2. Copy the folders in the tge15\engine folder of the zip into the engine folder of your TGE 1.5 installation
3. Apply changes in the tge15\diff.txt file
4. Open the Torque Demo solution in Visual Studio and add engine/python/pytorque.cc, engine/core/tDictionary.h, engine/core/tDictionary.cc to the solution
5. Select the Release build as the active project and change the build type from application to dynamic link library. Also, change the output file from TorqueDemo.exe to pytorque.pyd
6. Change the code generation to "Multi-threaded DLL" for the glu2d3d, ljpeg, lpng, lungif, opengl2d3d ,zlib, and Torque Demo projects
7. Add C:\Python25\include to the additional header directories for the Torque demo project
8. Add C:\Python25\libs to the library directories for the Torque demo project
9. Clean all and rebuild the Torque Demo project, you should end up with a pytorque.pyd file in the example folder of your TGE 1.5 installation
10. Copy tge15\example\TorqueDemo.py into the example folder of your TGE 1.5 installation and double click it
Example Usage
#--- Torque Python Module Example --- #Torque as a standard Python extension (no longer a executable) import pytorque from pytorque import TorqueObject #initialize pytorque, this also executes main.cs and the .cs packages pytorque.initialize() #example of executing a script file f = file("myscript.cs","rb") script = f.read() f.close() pytorque.evaluate(script) #or, just generate the cs code right inside Python! pytorque.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"; };""") #it's easy to grab a reference to the button we created button = TorqueObject("MyButton") #buttons are kind of worthless without commands. Let's make one: def OnMyButton(value): print "Button pushed with value",value #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 pytorque.export(OnMyButton,"MyButton","OnButton","Example button command",1,1) #we can get and set fields (including dynamic fields). We'll set our button's command: button.command = "MyButton::OnButton(42);" #we can call console methods on our TorqueObjects... So, let's simulate a button click. #the OnMyButton function will be called with the value 42 :) button.performClick() #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. #moving on, we can get and set global variables pytorque.setglobal("$MyVariable",42) print pytorque.getglobal("$MyVariable") pytorque.evaluate('echo ("*** Here is your variable:" @ $MyVariable);') #the main loop is broken out and can be combined with other frameworks rather easily while pytorque.tick(): pass #cleanup pytorque.. goodbye! pytorque.shutdown()

