Game Development Community

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

About the author


#1
12/17/2003 (1:09 pm)
You need to do something along these lines :
%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)
#2
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
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
#5
12/17/2003 (1:35 pm)
Blimey, your not kidding !

Thanks all!

Pj
#6
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.