Game Development Community

Custom Component Registration Order

by Aaron Scovel · in Torque X 2D · 11/04/2010 (8:59 pm) · 2 replies

By default components are registered in the same order as its owners objectID (the order they were added to the txscene). Is there a way to sort them based on a variable in the component before registering them?

My game has 100 pieces on a game board and some of my "piece objects" are out of order. This was never an issue since I add the component data to an array and then sort the array based on an order variable supplied by the component, but now I have came to a point in my game were I need them registered in this order as well for some on_register code to prevent "groups" of the same piece types from being randomly generated on the board.

It would be nice to have a solution to this so I don't have to worry about the order the objects were added to the txscene (with 100 objects there is really no way to tell which was added 1st, 58th, etc. without clicking on each item in the object tree), it would save me and others with similar issues substantial time.

For now, I will re-arrange my 100 objects :|

Aaron

About the author

Previously a PHP/MySQL Programmer/Web Developer of 10 years. In Aug 2010 I decided to change careers, and this is were I landed! I also parent 3 kids full time. TopNotched.com


#1
11/05/2010 (3:36 am)
As far as I know it's all the same order as the .txscene file has them. It might be easiest to change the order that way rather than in TXB.
#2
11/07/2010 (7:44 am)
You can't really change the way components register, nor where they are in the component container other than adding them in order. This doesn't mean you can't do what you want to do though, you just have to be creative.

I've got a component that changes my T2DAnimatedSprite into a derived type to give a little bit of extra functionality. On mine, I have a single component that OnLoad clones the template it's on, copies the components to the new template(save itself), renames the template it's on, names the new one the old ones name, and finally deletes the old template.

You could probably detect if your components are put out of order and in a similar fashion rebuild the template the way you want it done.

Edit: Then again it seems you want to change the way objects are loaded. Hrmm, that's a hard one. It may be possible to reroute your OnRegister code. As in, have some sort of manager that gets informed by their on register which order they need to be in and a delegate to their real onregister method. This way you can call the manager to do it for you in the order you want.