Game Development Community

Failure trying to expose delegate to TXB

by Matthew Shapiro · in Torque X 2D · 09/24/2007 (4:48 am) · 2 replies

I'm not sure if I"m reading the small page wrong but here goes. I am using delegates as an easy method to change the type of projectiles that shoot out of my ship. I have my delegate declared in it's own file as:

namespace StarterGame
{
    public delegate bool FireProjectile(T2DSceneObject firingShip, float timeSinceLastShot);
}

(The logic behind having it in it's own was to have one file with all delegates in it. I'm new to the whole delegate thing so maybe this is incorrect).

Anyways so then I have another class called DefaultMisssileProjectile with the function:
public static bool FireDefaultMissile(T2DSceneObject firingShip, float timeSinceLastShot)
{
   // code here
}

Finally, I have a ShipFireComponent, which has a field "FireProjectile _currentProjectile;". That property is correctly being exposed to TXB through the normal means. However, the drop down list does not have my DefaultMissileProjectile.FireDefaultMissile delegate listed (or any delegate).

Now I read through the short page in the docs concerning exposing delegates but I can't seem to get it to work. The instructions say to create a property to expose the field, though it does not say exactly where this is supposed to go. So I tried putting it into the DefaultMissileProjectile class with:

//  Private variable
        private static FireProjectile _defaultProjectile = FireDefaultMissile;

        // Expose it to TXB
        [TorqueXmlSchemaType]
        static public FireProjectile DefaultMissile
        {
            get { return _defaultProjectile; }
            set { _defaultProjectile = value; }
        }

Oddly enough, the addition of this code did not trigger a schema update on TXB, nor does the property display the delegate in TXB.

So I am at a loss on what else to do to expose my custom delegate to TXB. Any ideas what I"m doing wrong?

#1
09/24/2007 (9:31 am)
I cut-and-pasted some of your code to try to figure out what was wrong, but I am getting the choice in the selection box, so obviously we're doing something differently.

I pasted the code into a component created with the T2DComponent template, but it seems like you're declaring a class separately. Do you have the [TorqueXmlSchemaType] tag on your class definition?
#2
09/24/2007 (2:50 pm)
Hah that was it! Good to know I had the idea right.

Thanks a lot! :)