Scroll: OnCreate vs. Manual Object Tree Traverse

edited May 2013 in Help request
I am sorry if the answer is somewhere deep in forum discussion.

My config is something like this:

[Tank]
ChilList = TankHealthBar # obj1 # obj2

[TankHealthBar@HealthBar]
Postion = (...)

I have a Scroll object bound to HealthBar. I can easily traverse the subtree of the tank, but I have to use a specific object name. In this case it is TankHealthBar. My code fails to find the child object TankHealthBar, if I pass HealthBar template name.

I think I have a number of options. I just want to make sure I am not missing something in here.

1. Make a parameter in my tank class for the name of the TankHealthBar. I actually use Roles or Aspects concept, so it will be a parameter on HitPontAspect object of the tank.

2. Traverse object tree with the orxObject_GetUserData and search for the HealthBar class instance instead of the orxObject_Name().

3. Use Scroll::OnCreate event in HealthBar class. Get the owner of the class and set self as the health bar of the owner. Thus there is no need to search for the object at a later time. In this case I am not sure if OnCreate is guaranteed to be called in some kind of order. Will the owner be set when child's OnCreate is called?

My current solution is option #2, but with the hardcoded name. I like the option #3 as I will write less code in this case.

Comments

  • edited May 2013
    Hi kulak,

    I'm afraid I'm not entirely sure to precisely understand what you want to do.

    If you tell us what you try to achieve, it might be easier for us to help you with that. :)

    Anyway, point 1) is usually a very useful technique, however I mostly use it to test a random object and know about his "properties", like IsButton, IsCharacter, IsWall, etc...

    Point 3), however, won't work for the child: when the OnCreate is called on it, it doesn't have a parent yet, however, when the OnCreate of the parent is called, its whole ChildList (and their own childs) will already all be initialized.
  • edited May 2013
    If you want to keep a reference of TankHealthBar in your C++ object Tank, here is what I'm doing...

    [TankHealthBar]
    ...
    TrackList = TankHealthBarCreated

    [TankHealthBarCreate]
    0 = Config.SetValue Live TankHealthBarID ^

    in the Tank class, when I need to update TankHealthBar (ie: in Update())

    I check if the reference is NULL, then I retrieve it via its ID saved in Live.TankHealthBarID.

    Unfortunately, you can't retrieve it in the Tank::OnCreate() because the TankHealthBarCreated track is not executed yet...
  • edited May 2013
    If you want it to be available for Tank::OnCreate(), you can also do it in code:
    TankHealthBar::OnCreate()
    {
      orxConfig_PushSection("Live");
      orxConfig_SetU64("TankHealthBarID", GetID());
      orxConfig_PopSection();
    }
    
Sign In or Register to comment.