Game Development Community

Mounting object when created in mission editor

by Will Burgers · in Torque Game Engine · 02/17/2006 (1:39 pm) · 3 replies

Hello, in my current project I have a streetlamp object that I would like to mount a bulb object to with a light. Here is my Streetlamp.cs:

//////
datablock ShapeBaseImageData(LampBulbImage)
{
shapeFile = "~/data/shapes/objects/lampbulb.dts";

lightType = "PulsingLight";
lightColor = "0.5 0.5 0.5 1.0";
lightTime = "1000";
lightRadius = "5";
};

datablock StaticShapeData(StreetLamp)
{
category = "StreetLamps";
className = "StreetLamp";
shapefile = "~/data/shapes/objects/streetlamp.dts";
mass = 500;
computeCRC = false;
emap = true;
isInvincible = true;
team = 0;
};

function StreetLamp::create(%data)
{
%obj = new StreetLamp() {
dataBlock = %data;
};

%obj.mountImage(LampBulbImage,0);

echo("CREATE LAMP");

return %obj;
}
////

I was under the impression that the "StreetLamp::create" function would be called when creating the object in the mission editor, StreetLamp does show up in the 'shapes' category, however when I double click and create it the streetlamp.dts itself is there, but not the bulb, and "CREATE LAMP" is never echoed.
What function is called when the mission editor creates one, or is there someother way I can mount this bulb to every streetlamp?

Thanks for any help!
Will

#1
02/17/2006 (3:38 pm)
Do this in 'onAdd(%this,%obj)' instead of 'create'. It gets called every time the object is loaded, instead of just once when you create it in the editor.

The object should already have been set by the time 'onAdd' is called (datablock and position have been set), and you can do any additional setup there. At least that's how I do it.
#2
02/17/2006 (3:56 pm)
Will

The ::create() function gets called only for datablocks, not individual objects. There is a StaticShapeData::create(%data) function in staticShape.cs that should get called when the mission editor creates one of these. In my experience, however, when you spawn an object out of the mission object creator from the folder called "Static Shapes", the mission editor actually creates a TSStatic object and calls TSStatic::create(%shapeName) in editorGUI.cs.

In either case, the argument passed to these functions is the name of the object that is being created, so you could probably write a check one of those functions for "StreetLamp" and have it call another function to create and mount your light.

Hope this helps!

Dave
#3
02/17/2006 (4:05 pm)
Heh, looks like Brian beat me to it!

Yeah, using onAdd looks like it does what you need, and it's definitely more flexible than checking for special cases in the editor creation functions.

Dave