Game Development Community

TorqueXmlSchemaType and enum values

by Ron Barbosa · in Torque X 2D · 03/31/2010 (4:38 pm) · 5 replies

Hey all...I've got a component that during it's life cycle will generate several particle effects.

Each particle effect is in a specific category. When this scene object reaches the end of it's lifecycle, I want each category to be able to have its particle mode set to a certain value.

This will allow the me to clean up all the particle effects when this scene object dies without stopping them short (marking them for deletion stops them from playing...I want to change them to be of mode "KILL" when the scene object dies).

But this mode is an enum type. I don't want it to be empty in TXB, I want the game's editor to be forced to select a value. So I want to provide a default, but I haven't been able to figure out how to default an enum type.

Any thoughts?
--RB

#1
04/01/2010 (6:49 am)
Hi Ron,

TXB assumes as default value the first item in the enum, so be sure to have it corresponding to the desired default value, like this:

public enum MyStateEnum
{
    DefaultValue,
    Zero,
    One,
    Two,
    Three
}

private MyStateEnum _myState = MyStateEnum.DefaultValue;

public MyStateEnum MyState
{
    get
    {
        return _myState;
    }
    set
    {
        _myState = value;
    }
}

The above code gives you the desired result ;)

Pino
#2
04/01/2010 (7:24 am)
Thanks, Pino...the only problem with this is that it is not a custom Enum that I have created. It is the enum for the Particle Effect modes (Infinite, Cycle, Stop, Kill).

The other problem is that the default value would/could change for different components. So in the case of destructible components, the default value might be "KILL" for objects that have been destroyed.

But for another object that issues a constant particle stream, the default value might be "INFINITE." So I could modify the enum in the source code for TX, but that doesn't really solve my problem.

Consider this:

[TorqueXmlSchemaType(DefaultValue = "1.0")]

and:

[TorqueXmlSchemaType(DefaultValue = "500.0")]

Both of these are floats, but the default values are different.

I need something like this for one component parameter:

[TorqueXmlSchemaType(DefaultValue = "KILL")]

and something like this for another component parameter:

[TorqueXmlSchemaType(DefaultValue = "CYCLE")]

TX doesn't seem to allow for this.

Hope that clarifies my question. Thanks for the help though!
--RB
#3
04/01/2010 (8:07 am)
I've used stuff like [TorqueXmlSchemaType(DefaultValue = "Centered")] with no problems.

[TorqueXmlSchemaType(DefaultValue = "Cycle")] should work just fine. Be aware that Enums are case sensitive though and in your above code you are putting it entirely in upper case.
#4
04/01/2010 (8:21 am)
@Duncan

Hmmm...I'm not sure if I tested all variations of character case, but I got assertion failures from TX for each particle effect that loaded. The assertion failure indicated that it was unable to convert the string value to the appropriate enum type value. This was odd to me, because I was pretty sure that native C# is able to do this conversion.

I had seen something like this in the past where I was setting values for objects that had not yet been registered, and TX didn't like that (resulting in the same assertion failure message).

I'll verify that I tried the appropriate case as defined in the TX source code (but I think I would have tried that).

I'll post my findings after I verify the case tonight.

Thanks for the responses!
--RB
#5
04/01/2010 (3:27 pm)
Thanks, Duncan.

Major rookie mistake. I guess of all the things I tried, I never tried assigning the exact case as is defined in the enum.

I think I got confused by the fact that in TXB, when creating/editing a particle, the pull down to set the type is in solid caps.

Assertion failure is gone...default values are appearing as expected.

Thanks
--RB