Game Development Community

Automatically add a dynamic field in Inspector?

by Robert Geiman · in Torque Game Engine · 10/17/2005 (2:46 pm) · 10 replies

I created a new datablock derived from TriggerData to be used in my maps. In the World Creator I can add a new Trigger, and choose my new datablock.

To use my new datablock I need to manually add a dynamic field to it via the World Introspector. However, I'd like have this dynamic field show up automatically, rather than manually entering it every time I add a new trigger.

I know how to do this when creating new object via script, but how can I have this done automatically when adding via the World Creator? I tried the code below, but it doesn't seem to do anything (no error messages in console either):

datablock TriggerData(MyTrigger)
{
   tickPeriodMS = 100;
};


function TriggerData::create(%data)
{
   echo("******************** TriggerData::create called ******************");

   switch$(%data)
   {
      case "MyTrigger":
         %obj = new Trigger() {
            dataBlock = %data;
            myDynamicField = 42;
         };
         return(%obj);
   }

   %obj = new Trigger() {
      dataBlock = %data;
   };
   return %obj;
}

Any ideas?

#1
10/17/2005 (3:13 pm)
Hmmm i may not know what i'm talking about... but where is %block coming from that the switch statement is evaluating?
#2
10/17/2005 (3:42 pm)
Ah, you are correct. This was actually corrected in my code, but not in my post. I've since changed it so it is correct.

But even with the fix, the TriggerData::create function is never getting executed. I have a echo command in the very beginning of the function, but nothing ever gets printed to the console.
#3
10/17/2005 (4:05 pm)
How is it being called?... is it supposed to be ONADD?
#4
10/17/2005 (4:33 pm)
Ramen, that I'm not sure. I've searched the forums and found mention of the ::create function which seems like it should do what I wanted. I figured it would be some kind of polymorphic function, where it is called automatically just by addding it to a script file. It appears not to be the case, though...

After reading your last post, I added this below my datablock declaration:

function MyTrigger::onAdd(%this, %obj)
{
   echo("!!!!!!!!!!!!!!!!!!!!! MyTrigger::onAdd !!!!!!!!!!!!!!!!!!!");

   // %obj is the object being added to the world
   // with %this datablock.
   %this.myDynamicField = 42;
}

I was hoping maybe onAdd could solve my issue, but it apparently is not being called either. I wish I could find some kind of documentation explaining how all of this is supposed to work...
#5
10/17/2005 (5:16 pm)
So basically... what you need to have done... is you are using the world editor to create a new trigger... and after it's been created... you want to run a function to customize that trigger, correct?

if so.. i'll play around and see if i can get that to happen here.
#6
10/17/2005 (5:23 pm)
Yes, I'm creating the trigger via the World Editor Creator. When I add my new trigger I need to add a new dynamic field to that trigger because my trigger code depends on this new field existing.

What I'm trying to do is have this new dynamic field created as soon as I place my trigger on the map via the editor. So when I go to the World Editor Inspector after creating the trigger, I automatically see the dynamic field in there and I can simply change the value if I want.

Right now I must take the step of manually adding this field via the World Editor Inspector, and I run the risk of mistyping the field name which would cause my trigger to not work.
#7
10/17/2005 (5:34 pm)
Hmm it's not calling the onadd, oncreate or anythinjg like that for me either. Still looking for ya :)
#8
10/17/2005 (5:36 pm)
Onadd works for other objects... but doesn't seem to work for triggers. I'm guessing that's not a callback it does.
#9
10/17/2005 (5:41 pm)
I think it's something you'll have to add support for in the C++... but you could just do something different. Make a static shape or something use that as a replacement. You can add the static shape.... and on it's onAdd, you can use that to spawn a new trigger with whatever data you need... and then delete the original static shape replacement object.
#10
10/17/2005 (5:59 pm)
Ah, thanks for all your help Ramen.

I think I'll try adding a new class in C++ for my new trigger. Sounds like the best option to me.

Thanks again!