Game Development Community

TGEA 1.7 Python Support

by Prairie Games · in Torque Game Engine Advanced · 03/29/2008 (11:28 am) · 75 replies

Hey all, been doing some R&D on a new project and wanted to try out the (awesome) new build system
included with TGEA 1.7

I also wanted to have a look at some embedded scripting... and so dusted off PyTorque, got it ported over to 1.7, changed it around to be an embedded system, and hooked it up with the new build system.

www.prairiegames.com/gg/tgea_python.jpg
There are only very minor changes necessary to the core engine to support Python scripting. It is pretty powerful stuff... the docs are a bit sparse, but if you head over to MMOWorkshop.com you can browse through a lot of examples...

BTW, this is a newer system than what was used for Minions of Mirth. It is actually quite a bit cleaner... so, when in doubt check out the included example.py :)

You can snag PyTorque for TGEA 1.7 HERE

This was a pretty quick package job... so, post here with any glaring issues.

-Prairie Games, Inc
Page «Previous 1 2 3 4 Last »
#1
03/29/2008 (2:23 pm)
Is this going to be dependent on the build version of TGEA 1.7?

Randy
#2
03/29/2008 (5:44 pm)
This is just what the doctor ordered, I was having all sorts of problems getting the old PyTorque to work. Thanks for sharing. =)
#3
03/30/2008 (9:11 am)
This is a great new, to be able to use the engine of the day this really a great new.
#4
03/30/2008 (9:59 am)
Oh man ... now my MMO R0X0RZ!!!! Thanks!
#5
03/31/2008 (5:19 am)
Thanks a lot, this will indubitably help with the streamlining of my RPG!
#6
04/05/2008 (8:11 pm)
Prairie Games is now my official GOD of TGEA / Python!
After searching all day, Finding this link in the search but unable to connect from the search ( seems i get logged out after clicking anything after a search ) Finally, this is the news i have been trying to reach and it only took me 14 hours 8 mins.

Thanks to Prairie Games for the efforts of MMOKit and keeping us on top with the Python fix too.
#7
04/05/2008 (9:25 pm)
I think there may be a bug in the PyTorque 1.7 implementations export function.

The export is used like this (from the example docs):

pytorque.export(OnMyButton,"MyButton","OnButton","Example button command",1,1)

Which is similar to the old TGEExport command with the old implementation which would have looked like:

TGEExport(OnMyButton,"MyButton","OnButton","Example button command",1,1)

Now the problem is if I try to call this function from script using:

MyButton::OnButton();

I receive this error:

(0): ::OnButton - wrong number of arguments.
(0): usage: Example button command

Now I noticed that the OnMyButton function was trying ot accept in a value, so that caused me to experiment with moving away the value and with changing the 1,1 to 0,0 or 2,2 just to make sure that the format didn't change there. I haven't dug in much deeper at this point as I need to go out tonight and didn't want to get any deeper into debugging just yet.

Am I using these wrong or is this a bug?
#8
04/06/2008 (2:24 am)
What happens if you call: MyButton::OnButton(42);
#9
04/06/2008 (4:30 am)
I get the same error:

(0): ::OnButton - wrong number of arguments.
(0): usage: Example button command

If I use a namespace that isn't set up then it returns output with the namespace in the front, but when I do it for one that does it gives the ::OnButton without the MyButton on the front when it hits the error (line 1287 of compiledeval.cpp). I went through all of the codeblock and compiledeval changes though since they dealt with the namespaces and they are the same as in the text file. The other functions all seem to work for me, I can set and read globals, I can eval, etc. But on exporting it's giving me issues.

NOTE: I also noticed that this line:

button = TorqueObject("MyButton")

also gives the following error:

NameError: name 'TorqueObject' is not defined

I commented out the button stuff as a result of that and just called it directly, which is where I received the wrong number of arguments error.
#10
04/06/2008 (8:39 am)
I was just reading over some of the new documentation and remembered seeing the button question come up in this thread. The 1,1 should be (if it correlates to the stock TGEA stuff) minimum args, maximum args. Of note, though, is that the examples I saw (TorqueScript, I believe) always had a minimum of 1 due to the default passing in the function name. If the button takes an argument, then perhaps try:

changing the 1,1 to 2,2
AND
try what Josh said...

pytorque.export(OnMyButton,"MyButton","OnButton","Example button command",2,2)
...
MyButton::OnButton(42);

Maybe one without the other won't work, but the combination will..

just a thought..

btw.. I have a quick question to Josh. If I understand the TMMOKIT correctly, and not counting the python-only server components - just the sim server component, a zone server is a python application that runs the TGE as a module. The TGE module handles the simulation (physics-wise, etc) for the outer python app which handles everything else.

Now, if I understand this mod, then the sim would be the TGEA application, with scripting handled by python on the inside of the engine.

How do you suspect performance will be affected by that change (almost like a complete swap)? As opposed to the zone server being a python app with an instance of TGE running inside it, do you plan on making your future zone server a running TGEA app with python scripting inside of it? Is it possible you pan on mixxing the two, by creating a python zone server, running a TGEA instance inside of it (doing the bulk of the work out in python as with MoM), and also allowing the TGEA scripting to be in python (a TGEA sandwich, so to speak)?
#11
04/06/2008 (9:06 am)
@Keith: Yeah I've tried changing the number of arguments on it, but no matter what setting I use or what setting I ask the funciton to take I get the error when actually trying to use the function. It exports without an error, but when using it I always receive the wrong number of arguments. The part that is interesting is that it doesn't have a value for the namespace name, the error should be returning

(0): MyButton::OnButton - wrong number of arguments.
(0): usage: Example button command

but instead it reports

(0): ::OnButton - wrong number of arguments.
(0): usage: Example button command

Which makes me believe it is namespace related, but i've made all of the namespace changes for codeblock and compiledeval, double, and triple checked them.

I guess a good question would be to ask if anyone has been able to get this working and have had the export or the TorqueObject commands working properly?
#12
04/06/2008 (9:30 pm)
On a sidenote I noticed that you could export without using a namespace, so I tried that, but received the same error.
#13
04/07/2008 (2:52 am)
This is likely a bug introduced in the port or 1.7 handling the console a tad differently.

If you figure it out, please post your findings :)
#14
04/07/2008 (7:11 am)
So I played around with this a bit today between work. I modified the addcommands to have a ,false at the end, because of the new isToolTip boolean at the end. And then by playing with some values I was able to get it to recognize the function. So basically the addcommands look like:

Con::addCommand(ns,fname,cTorqueToPythonCallback,usage,minargs,maxargs,false);

and

Con::addCommand(fname,cTorqueToPythonCallback,usage,minargs,maxargs,false);

If you are trying to integrate it with Prairie Games MMO Kit making the minargs, maxargs a -1 will have it expect the correct number of arguments.

This works fine for things with 0 arguments. But when you start dealing with multiple arguments it started to give some issues. Here's an example block of code to illustrate the issue:

def OnMyButton(val):
    print "Button pushed with value",val
    
def OnMyButtonPlain():
    pytorque.evaluate('echo("command set plain");')    
    
pytorque.export(OnMyButton,"MyButton","OnButton2","Example button command",2,2)
pytorque.export(OnMyButton,"MyButton","OnButton3","Example button command",3,3)
pytorque.export(OnMyButtonPlain,"MyButton","OnButton","Example button command",1,1)

So basically in this case we have MyButton::OnButton expecting 0 arguments (because I'm doing a -1 to the min/maxargs in my code as I mentioned above to fit the kits standard) and that will soimply display command set plain. Where MyButton::OnButton2 should be expecting one value and then using printing to our python console Button Pushed with value (argument value). This does not work however, as we'll see below. MyButton::OnButton3 is expecting two arguments, and if we pass it two arguments it then goes through and displays correctly, even though the function is only taking one argument.

Example of output:

Input: MyButton::OnButton();
Output: command set plain

Input: MyButton::OnButton2(4);
Output: OnMyButton() takes exactly 1 argument (0 given)

Input: MyButton::OnButton3(1,2);
Output: Button pushed with value 1

So with 0 arguments its processing correctly, but its expecting the input to have one extra value at the tail end. I'm done for the night but will get back to this tomorrow if noone else does.
#15
04/08/2008 (2:04 am)
Also for the TorqueObject, in the docs example it uses this line:

button = TorqueObject("MyButton")

That won't work but so long as you call it as:

button = pytorque.TorqueObject("MyButton")

Then it will work fine.
#16
04/08/2008 (6:38 am)
From pytorque import *

or

from pytorque import TorqueObject

could be added to the example, but it is mostly meant for usage examples and not to actually be run.

Regarding the arguments for exported functions, yup looks like something is funky... I won't have time to look into it for a bit. It probably is something relatively small/simple... please post if you find the fix :)
#17
04/10/2008 (12:46 am)
That goes to show you how much I studied up on Python. I've used it for a while now with the kit, but have only read about it when I ran into problems. For the most part its an easy language to pick up. But I never understood what the from ___ import ___ was useful for. My assumption was that it only imported specific functions and wasn't necessary in a lot of cases. I had just been using import ___ and thus needed to use the pytorque namespace.
#18
04/10/2008 (11:44 am)
Am I the only one having this problem?

------ Build started: Project: PyTorque, Configuration: Release Win32 ------
Compiling...
pytorque.cpp
..\..\..\source\pytorque.cpp(236) : error C2039: 'sfnNameSpace' : is not a member of 'CodeBlock'
c:\Torque\TGEA_1_7_0\engine\source\console/codeBlock.h(18) : see declaration of 'CodeBlock'
..\..\..\source\pytorque.cpp(236) : error C2065: 'sfnNameSpace' : undeclared identifier
..\..\..\source\pytorque.cpp(238) : error C2039: 'sfnNameSpace' : is not a member of 'CodeBlock'
c:\Torque\TGEA_1_7_0\engine\source\console/codeBlock.h(18) : see declaration of 'CodeBlock'
..\..\..\source\pytorque.cpp(238) : error C2065: 'sfnNameSpace' : undeclared identifier
..\..\..\source\pytorque.cpp(609) : error C2039: 'iterateMainLoop' : is not a member of 'StandardMainLoop'
c:\Torque\TGEA_1_7_0\engine\source\app/mainLoop.h(13) : see declaration of 'StandardMainLoop'
..\..\..\source\pytorque.cpp(609) : error C3861: 'iterateMainLoop': identifier not found
---

I'm trying to compile with visual C++ 2008, those members don't exist ... Maybe it got changed before the official release (after beta tests) ?
#19
04/10/2008 (11:47 pm)
You need to merge in the changes in the tgea17/tgea17 file into the various files. The sfnnamespace changes and standardmainloop changes are in that file. Basically the lines that start with a + are the new code, and the stuff around them are there to show you where it should go, patch file style.
#20
04/14/2008 (9:43 pm)
Thanks for this! Being able to use Python with Torque is totally awesome.

I am having a very strange error, and am hoping someone can help with this.

I am attempting to export a very simple function in main.py. It is unchanged from the original main, except I added these lines...

# TESTING #####
def PyHelloWorld():
pytorque.evaluate('echo("Hello world.");')

pytorque.export(PyHelloWorld, None, "PyHelloWorld", "Just has python echo to the console.", 1, 1)
############

... immediately before "while pytorque.tick():"
When I try running PyTorque.exe, it crashes with the following at the end of the console log:

Engine initialized...
PyTorque - TGEA 1.7 - Win32 - Starting Up
Error, a DecalManager (1d27c38) isn't properly out of the bins!

When I comment out those added lines in main.py, PyTorque runs fine!
I find this totally bizarre. Has anyone run into anything like this?
Page «Previous 1 2 3 4 Last »