Game Development Community

OnRegister

by Vishal Bhanderi · in · 10/05/2008 (2:19 am) · 4 replies

Hey Guys,

On page 31 it talks about a OnRegistered drop down box in TXB, where we can specify a method to call when the scene object is created. How do we go about creating these methods? Since i'm only making components and not whole scene objects.

Thanks

Vishal

#1
10/07/2008 (12:11 pm)
LOL - I don't actually have a copy of the book with me now, so I'll need to check this tonight. But, you can create your own delegate method that is called when a scene object is created; it just needs to match a specific delegate signature, which I'll post later. In the meantime, are you creating components that will not be attached to any scene objects at all? If you can describe the problem, I might be able to point you in a better direction.

John K.
#2
10/07/2008 (12:59 pm)
What I'm trying to do is get a drop list. For example 'stone', 'arrow' or 'bullet'. Then the components attached to the object can see what value in the list is and act on that.

So in TXB a drop down.

Stone
Arrow
Bullet

Then in the C# code i would check which of the values are selected and execute code relating to it. Like:

if (dropDown equals "Stone")
....
else if (dropDown equals "Arrow)
...

I thought this would be my answer to my problem here:

www.garagegames.com/mg/forums/result.thread.php?qt=70936

I think I'm missing something big here.

Vishal
#3
10/10/2008 (9:38 am)
Vishal, I'm sorry if I'm not fully understanding your question. But, it really sounds like you can do this with thestock TorqueObjectTypes. Just like the Breakout game in the book, start in Torque X Builder 2D by clicking a blank area (or pressing escape). Then under the Scene Data rollout, create 3 new "Object Types"... call them Stone, Arrow, and Bullet - pressing the green add button for each. Then, for your game scene objects or projectiles, in the Scripting rollout, select one of those from the dropdown list there and press the green add button.

Now that your object has the type associated with it, your C# code can test for that type. Using your component code fragment above, it might look like this...

TorqueObjectType typeStone = TorqueObjectDatabase.Instance.GetObjectType("Stone");
            TorqueObjectType typeArrow = TorqueObjectDatabase.Instance.GetObjectType("Arrow");
            TorqueObjectType typeBullet = TorqueObjectDatabase.Instance.GetObjectType("Bullet");

            if (owner.TestObjectType(typeStone))
            {
                //do something for a stone
            }
            if (owner.TestObjectType(typeArrow))
            {
                //do something for a arrow
            }
            if (owner.TestObjectType(typeBullet))
            {
                //do something for a bullet
            }

Does this work out for you, or are you trying to do something else?

John K.
#4
10/10/2008 (12:26 pm)
I think I'm not explaining myself well. I was planning on having a drop down box on the AI object or even the AIComponent. Then I would select the type of projectile it will fire in a drop down box. Then in the code for the AI, I would do certain actions depending on the value in the drop down. For example if the drop down had "Rock" selected then the AI would fire rocks with a certain trajectory and speed.

I hope I make more sense now.

Vishal