Game Development Community

Creating objects in editor, referencing in script

by Dan Roy · in Torque Game Builder · 01/17/2007 (8:27 pm) · 4 replies

I've been using TGB for a while now, but one thing I haven't been able to figure out. When I create lots of objects in the level editor, and I give them all the same class, and I want to give one of them a name so I can manipulate it from script (mount and unmount), I set the "name" of the object in the editor under the scripting section. This name, however, doesn't seem to be valid when I get back to script. In fact, the TGB example/tutorial seems to rename the object in script:

$player = %this;

... as opposed to taking the name "player" from the editor. What's the best way to do this? Yes, I could hack it and just search through every object of that class in script and find the one that has some code that I put in under "Dynamic Fields," but I've been doing that for a long time and think there must be a better way. How do I use this "name" field in the scripting section of the editor?

Thanks.

#1
01/17/2007 (9:14 pm)
You can reference globally by name.

new t2dStaticSprite(mySprite)
{
    scenegraph = myScene;
    // ... etc
};

// then you can just say
mySprite.position();

Does that make sense?

#2
01/17/2007 (9:44 pm)
Thanks!
#3
01/18/2007 (1:49 pm)
The usual mistake is to put a % or $ before the name. If you put "myBlob" in for the Name field, you can reference the object just with myBlob:
myBlob.explode();
#4
01/18/2007 (1:51 pm)
I did in fact make both of those mistakes. Thanks for the clarification.