Game Development Community

Python + T2D = Yummy

by Tomas Dahle · in Torque Game Builder · 03/26/2005 (12:15 pm) · 24 replies

Well, after a few days of digging around with the engine I've finally managed to polish my TGEPython based PyT2D enough to run the entire tutorial perfectly.

Now I am NOT going to spend even half a second at this point telling people that they should use Python instead of TorqueScript. All I want to do is show it and invite anyone that has a bit of familiarity with python and preferably C++ as well to test it out with me.

Anyone that wants to try out PyT2D, just e-mail me at tomas@cakefish.com. It's pretty smooth right now, but I certainly expect more peculiar issues to arise, so I only want people that are a bit resourceful and wish to help me work it out to try it out at this stage.

Feel free to ask any question about PyT2D here, I'm happy to answer :)

Example code, straight from the Tutorial follows:

(you will correctly notice that I only included some of it, but the entire tutorial does work)
Page «Previous 1 2
#1
03/26/2005 (12:17 pm)
from PyT2D import *
import random

def PyExec():
    SetupImages()
    CreatePlayer()
    CreateEnemy()
    CreateTileMap()

def SetupImages():
    datablock("fxImageMapDatablock2D",
              name = "playershipImageMap",
              mode = "FULL",
              textureName = "T2D/client/images/playerShip")
    datablock("fxImageMapDatablock2D",
              name = "enemyship1ImageMap",
              mode = "FULL",
              textureName = "T2D/client/images/enemyship1")

    ETC...

def CreatePlayer():
    global player
    global playerMap

    player = new("fxStaticSprite2D",
                 scenegraph = "t2dSceneGraph")
    
    player.setPosition((-35, 0))
    player.setSize((14, 7))
    player.setImageMap("playershipImageMap")
    player.fireLinkPoint = player.addLinkPoint((0.45, 0.2))
    player.setWorldLimit("clamp", (-49, -37, 40, 37))

    attachThruster(player, (-0.12, -0.33), 0)

    ETC...

def attachThruster(mountObj, mountPosition, angle):
    #Create Player Thruster.
    thruster = new("fxParticleEffect2D",
                   scenegraph = "t2dSceneGraph")
    thruster.loadEffect("T2D/client/effects/smallThruster.eff")
    thruster.mount(mountObj, mountPosition, 0, "false")
    thruster.setRotation(angle)
    thruster.playEffect()

@export()
def playerUp():
    #Set the player moving up.
    global player
    player.setLinearVelocityY(-10)

@export()
def playerUpStop():
    #If we're moving up then nullify any upward movement.
    if player.getLinearVelocityY() < 0:
        player.setLinearVelocityY(0)

def KillPlayer():
    player.setVisible("false")
    playerMap.pop()
    T2D.schedule(2000, 0, "ResetPlayer")

@export()
def ResetPlayer():
    player.setPosition((-35, 0));
    player.setVisible("true");
    playerMap.push();

@export(namespace = "fxSceneObject2D")
def onCollision(self, srcObj, dstObj, srcRef, dstRef, time, normal, contactCount, contacts):
    #Manually convert these to an object
    srcObj = T2D.obj(srcObj)
    dstObj = T2D.obj(dstObj)

    #Create an explosion for the collision that just occurred
    createExplosion(dstObj);

    if (srcObj.getID() == player.getID()):
        KillPlayer()
        dstObj.safeDelete()
    elif (dstObj.getID() == player.getID()):
        KillPlayer()
        srcObj.safeDelete()
    else:
        srcObj.safeDelete()
        dstObj.safeDelete()
#2
03/26/2005 (12:55 pm)
Wow, I'm drooling. :) You mean we get all the benefits of Python along with this? Great work!

BTW, how does this work? What steps are necessary to use Python with T2D?
#3
03/26/2005 (1:44 pm)
Hey cool Tomas! You should make this a resource, if you get a chance. People will definitely test it out that way. :)
#4
03/26/2005 (2:11 pm)
Joshua Ritter will be proud ;p
#5
03/26/2005 (2:16 pm)
Here's what I want to know. Where did you hook all this stuff in? I might be interested in doing something similar for Lua.
#6
03/27/2005 (12:12 am)
@Jason: Yep, you get all the benefits of Python. All you have to do is add a few files in it's own subdir in the 'engine' dir and recompile. Yep, that's right, no T2D source files are modified.

@Josh: You bet I am going to make a reource out of this, but first I want to smoothen things out a bit. I'd had to put out a resource that can't be used even by novices.

@Smaug: Check out TGEPython, which I based this on for implementation details. I've modified it slightly, but the basics is there.

A few people have already shown their interest in this, but feel free to e-mail me (address above) still if you want to help me try it out. Personally I'm going to plunge into my game now to give PyT2D a real good spin.
#7
03/27/2005 (9:34 am)
@Tomas: Sounds great! I'll be looking at this when you get things ironed out.
#8
03/28/2005 (6:50 pm)
I'm really interested in using this, so I thought I'd fuel the fire and mention that there's a nice IDE based on Eclipse called Pydev. Good stuff!
Quote:New Release: 0.9.1!!

* Lot's of 'sugar' in this release... Code Formatter (simple, but already useful) - Ctrl+Shift+F
* Organize imports/selection alphabetically - Ctrl+Shift+O
* Keep your 'quality standards' with PyLint 0.6.3: now it only locks the interface whan updating results.
* Content Assistants: They now have icons!!
* Scott Schlesier provided a patch for the editor preferences! It is much better now!
* Code completion has been improved!
#9
03/28/2005 (6:59 pm)
I want to eventually do the same thing for PHP, but time is tight right now. I'm really glad to see how quickly you were able to get the Python linkage working.
#10
04/11/2005 (2:17 pm)
Any progress on this, Tomas? I emailed you, but maybe your spam filter ate it. :)
#11
06/05/2005 (2:00 am)
I'd wish Tomas' email address would work ... ?
#12
06/07/2005 (3:21 pm)
I don't think they're working on it much, anymore, sadly.

I plan to attempt this myself, though, so if anyone else wants to join forces to bring Python to T2D, please let me know. I want to use this very soon for my next project.
#13
06/07/2005 (5:16 pm)
@Jason: I would like to join you there as I also want to use it for my next project. I left you a message on the GrimInv website some time ago. If you can't find it, please contact me at the email-address in my profile. How is your 'little gods' project going btw?
#14
06/07/2005 (5:53 pm)
@Edo: Sounds good. I just got your message today because I moved and was away from internet access for far too long. :) Please email me, and let's get started.

If anyone else wants to join this project, please feel free to contact me. I'll take all the help I can get.
#15
06/07/2005 (7:59 pm)
BTW, my email address is "jason at griminventions.com". :)
#16
08/05/2005 (4:43 am)
Well it is true that I haven't been working on this for a while. I handed the development of this over to someone else who made many promises and made me wait for updates. Updates never came.

So, I guess it's time to take things into my own hands again. Python for T2D is almost flawless already btw, and has been for over half a year. All we need is people to try it out and I'm sure it will work out fairly well.

Btw, are someone trying to email me without me receiving?
#17
08/06/2005 (3:00 pm)
There's no sound support and scheduling with arguments doesn't work. I've tested it quite thoroughly, and those are the issues Edo and I intend to address ourselves very shortly unless someone beats us to it.
#18
08/06/2005 (3:07 pm)
I'd be interested in knowing how you went about this technically speaking.

for T2D.NET, I directly call the C++ wrapper functions and have the C++ functions call C#.

How did you get Python working?
#19
08/06/2005 (4:02 pm)
Jason Swearingen: A hint - I can't remember exactly, but if you do download the python thing Ritter made for TGE you will see the idea clearly. It's a fairly smart approach. Too bad in the end, replacing the scripting engine isn't really going to change much - which i found out myself.

Jason McIntosh:
Scheduling with arguments worked fine for me. But I do remember there was some sort of magic mumbo jumbo to take note of. As for sound, I never tried that.


I have to admit looking at t2d and pyt2d for a few hours yesterday discouraged me further. Since there has been no update in ages the same things that I lacked then is still the case. Maybe I'll pop back here in a year and see if the engine i paid tons of cash for can do something that means something to me by then.

I can use python with t2d, but i can in no way make t2d pythonic. And the reason I love python beyond anything programming-related is because I like things to be pythonic. So byebye t2d.
#20
08/06/2005 (4:20 pm)
Quote:Scheduling with arguments worked fine for me.
You don't happen to have an example of the magic mumbo jumbo lying around, do you? :)

Quote:I can use python with t2d, but i can in no way make t2d pythonic.
I think that's to be expected, but it's a far better situation to have Python as the script language than TorqueScript. Sorry to hear you won't pursue PyT2D anymore. Looks like Edo and I will pick up the torch and run with it. ;)
Page «Previous 1 2