Exposing lists and structures to TXB
by Adrian Cheater · in Torque X 2D · 10/19/2007 (12:36 pm) · 3 replies
Hi,
I've got two issues with TorqueX that I'm trying to solve. They're for different problems, but somewhat related.
Problem #1:
I want to be able to set the rotation offsets for link points from within TXB. Currently they default to 0, with no way to edit them. They can be manually changed afterwards, but if you re-open the txscene file and re-save, it will reset the rotations back to 0.
Is there any way to get the position and/or rotation values for each link point to display in the "Link Points" section of the component sidebar? Or alternatively, since I'm a TorqueX Pro user, is there any way to modify the the T2DLinkPointComponent so that it will export those properties through its component sidebar?
Problem #2:
I want to create a component which manages resource production. Since you can only install one component on an object, ideally I'd like to be able to have a component manage multiple resources. A resource has a name (string), current value (float), maximum value (float), and regeneration rate (float).
What I'm looking for is something similar to the collision materials setup in the "Scene Data" portion of TXB, where I can specify the values, and clikc the "+" button to add it into a list. Is that functionality driven by the TXB schema, or is it hardcoded into TXB?
Are there any white papers available on the TXB schema, and the component exposing interface?
Thanks for your time,
Adrian
I've got two issues with TorqueX that I'm trying to solve. They're for different problems, but somewhat related.
Problem #1:
I want to be able to set the rotation offsets for link points from within TXB. Currently they default to 0, with no way to edit them. They can be manually changed afterwards, but if you re-open the txscene file and re-save, it will reset the rotations back to 0.
Is there any way to get the position and/or rotation values for each link point to display in the "Link Points" section of the component sidebar? Or alternatively, since I'm a TorqueX Pro user, is there any way to modify the the T2DLinkPointComponent so that it will export those properties through its component sidebar?
Problem #2:
I want to create a component which manages resource production. Since you can only install one component on an object, ideally I'd like to be able to have a component manage multiple resources. A resource has a name (string), current value (float), maximum value (float), and regeneration rate (float).
What I'm looking for is something similar to the collision materials setup in the "Scene Data" portion of TXB, where I can specify the values, and clikc the "+" button to add it into a list. Is that functionality driven by the TXB schema, or is it hardcoded into TXB?
Are there any white papers available on the TXB schema, and the component exposing interface?
Thanks for your time,
Adrian
About the author
#2
Then, inside my BlahComponent, add the a private List collection variable that will hold these resources...
Then, at the top of the BlahComponent, create the accessor property that exposes this List to the Torque X Builder tool...
Now rebuild and open up Torque X Builder. Add the BlahComponent to your object and expand its properties. When you expand the BlahComponent properties, you should see a block called SomeThings Under that, there are 4 text fields to enter your values. Now, all you need to do is enter the values and then click the green Add button next to the AdriansResourceClass list. Anytime you want to, you can move each entry up or down, edit it, or delete it.
Torque X Builder seems to use reflection to scan through the component class and interpret it's members to create the dynamic editor. Now that is really cool!!!!
John K.
10/19/2007 (2:57 pm)
Okay, I just threw this togethter and it works pretty good. Start off by creating your own resource class like this... (I just added this class to the top of my own BlahComponent)public class AdriansResourceClass
{
public string Name;
public float Current;
public float Maximum;
public float Regeneration;
}Then, inside my BlahComponent, add the a private List collection variable that will hold these resources...
List<AdriansResourceClass> _things;
Then, at the top of the BlahComponent, create the accessor property that exposes this List to the Torque X Builder tool...
public List<AdriansResourceClass> SomeThings
{
get { return _things; }
set { _things = value; }
}Now rebuild and open up Torque X Builder. Add the BlahComponent to your object and expand its properties. When you expand the BlahComponent properties, you should see a block called SomeThings Under that, there are 4 text fields to enter your values. Now, all you need to do is enter the values and then click the green Add button next to the AdriansResourceClass list. Anytime you want to, you can move each entry up or down, edit it, or delete it.
Torque X Builder seems to use reflection to scan through the component class and interpret it's members to create the dynamic editor. Now that is really cool!!!!
John K.
#3
Also, to clarify on the "Can't add more than one Component". I meant that I can't add more than one instance of the same component. So understanding the use of the List object as a means to expose structures to TXB will be key to some of the things I'm doing. Thanks again!
EDIT: It works, it's easy, and it's exactly what I was looking for. Thanks a ton!
10/19/2007 (8:42 pm)
I'll give this a shot on Monday. If I can get it to work, I should be able to also apply your solution to get the Link Point data structures to expose themselves through a custom T2DLinkPoint component. Thanks very much for your suggestions, and I'll let you know how it turns out.Also, to clarify on the "Can't add more than one Component". I meant that I can't add more than one instance of the same component. So understanding the use of the List object as a means to expose structures to TXB will be key to some of the things I'm doing. Thanks again!
EDIT: It works, it's easy, and it's exactly what I was looking for. Thanks a ton!
Associate John Kanalakis
EnvyGames
How about creating a derrived class from T2DLinkPointComponent, called T2DLinkPointComponentExtended that only exposes those properties?
Problem 2.
I don' think I really understand this one. An object can have any number of components attached to it, not just one. I also am not clear on what a 'resource' is, do have a specific example? I think there is a way to have a component that accepts multiple inputs, like the button list you described. You might have to create a public property based on the List collection class. I'll take a quick look.
John K.