How to spawn objects programmatically ?
by Pj · in Torque Game Engine · 12/17/2003 (12:59 pm) · 7 replies
Hi there
Just brought the SDK and am still feeling my way around so sorry if this is a dumb question, but I've searched the forums and docs and can't find anything relevant:
How can I 'spawn' an object programmatically (i.e., through script or code) at a position on the play area, say at the players position.
Pj
Just brought the SDK and am still feeling my way around so sorry if this is a dumb question, but I've searched the forums and docs and can't find anything relevant:
How can I 'spawn' an object programmatically (i.e., through script or code) at a position on the play area, say at the players position.
Pj
#2
I shall go play about with it...
Pj
12/17/2003 (1:16 pm)
Thanks James, thought it would be something simple like that!I shall go play about with it...
Pj
#3
12/17/2003 (1:16 pm)
Here's some code that should do it from C++.Item *joe;
ItemData *theData;
joe = new Item;
Sim::findObject((const char *) itemName, theData);
joe->onNewDataBlock(theData);
if (joe->registerObject())
{
}
else
{
delete joe;
joe = NULL;
}
#4
tork.zenkel.com/tge_snipits/view_snipits_in_category.php?fk_tge_snipit_category_...
EDIT: doh, some guys are pretty darn fast around here :P
12/17/2003 (1:17 pm)
Here is how to add an item in C++:tork.zenkel.com/tge_snipits/view_snipits_in_category.php?fk_tge_snipit_category_...
EDIT: doh, some guys are pretty darn fast around here :P
#6
( on the line Sim::findObject((const char *) itemName, theData); )
Thanks!
Sam.
08/04/2004 (7:58 am)
Can you explain what I should use as itemName?( on the line Sim::findObject((const char *) itemName, theData); )
Thanks!
Sam.
#7
08/05/2004 (8:51 am)
The name of the datablock, or its id.
Associate James Urquhart
%foo = new MyShape(ShapeName) { dataBlock=MyShapeDataBlock; }; MissionCleanup.add(%foo); %foo.setTransform("x y z"); // Do more stuff here....Where "MyShape" is the name of your Shape class. Unless you made a new ShapeBase derivative with new behaviour (or your spawning a vehicle / player), either in code or script, it should be ShapeBase.
Look in the demo scripts for more detailed examples (e.g the crossbow spawning particles)