Game Development Community

Using TorqueXmlSchemaType to set multiple default values

by John Nguyen · in Torque X 2D · 01/29/2009 (11:27 am) · 3 replies

Is there a way to set default values for all variables in an object when using the TorqueXmlSchemaType?

For example,

[TorqueXmlSchemaType(DefaultValue = "50")]
public Vector2 Direction
{
get { return _direction; }
set { _direction = value; }
}

This defaults X to 50 (as seen in my Direction X field in TXB). The problem is that _direction also has a Y variable too. How do I set the Y variable?

About the author

Recent Threads

  • LoadMainMenu()

  • #1
    01/29/2009 (11:54 am)
    The documentation says this:

    For properties with multiple fields, like a vector, each field should be separated by a space. So a Vector2's default value would look like this: DefaultValue = "1.0 2.0".

    Though I tried that and it still does not display correctly in the TXB. It might take in code though I did not try that.

    Another thing you could do is represent that vector as an angle which would just be a single float value.

    and in the get method you could do return T2DVectorUtil.VectorFromAngle(_direction);

    but you really should not have to do that unless there is some kind of bug in the TXB that does not allow multiple values.. in which case the documentation is also incorrect.
    #2
    01/29/2009 (12:32 pm)
    I tried the space thing, and it didn't work, so I thought I was doing something wrong somewhere.

    I'll try your suggesting.

    Thanks a bunch
    #3
    01/29/2009 (2:04 pm)
    This is exactly how it is in one of the files that comes with Torque (just in case you have a slight syntax error):

    [TorqueXmlSchemaType(DefaultValue = "200 200")]

    Though from the sound of it you've got this part right.