How do I select an family's instance based on its variables

0 favourites
  • 3 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hello,

    This is a pretty basic thing I am trying to achieve. Still, I can't manage to do it properly. I even thought about posting it in beginner's questions forum but well...

    So I have a family "allies" with 4 object in it : "knight", "berserker", "archer" and "sorcerer". There is a "char" family instance variable, and I defined it to the exact name of the object. So to be clear the "knight" object's "char" variable is defined to "knight", and same for the 3 other objects.

    Now all I want to do is select one of the alive allies at random and know its char value in order to apply a function to him.

    I do :

    Allies health > 0 ("health" is another family instance variable of course)

    (in a subevent) Pick a random allies instance (up to there everything is working fine, I have checked in the debugger)

    (subevents of the previous subevent) Allies char = "knight" --> do something

    Allies char = "berserker" --> do something

    Allies char = "archer" --> do something

    Allies char = "sorcerer" --> do something

    If I'm correct, the "do something" part should apply only to the instance picked at random, but it actually never triggers, for none of the allies.

    Any idea of what I am doing wrong and how I could fix it?

    Thanks in advance!

  • Is this event triggered every tick?

    What is the "do something" ?

    Could there be conflicting events, reversing the "do something"?

    Seems like it should work:

    FamilyByInstanceVariable.capx (r218)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • EDIT : by analysing your capx I've been able to solve the problem! I previously defined the "char" values in each object's properties in the layout. Despite the fact that the values were correct in the debugger, defining all the values on the start of layout like you did fixed the problem.

    Curious, as doing the same in your capx actually works... I should have missed something here.

    Anyway, thanks a lot!

    ---------------------------

    Hi LittleStain and thanks for the answer.

    • The event is triggered once every few seconds
    • "Do something" is normally a function reducing the character's life, but for test purpose, the knight action just says "delete knight", the archer action is "delete archer" etc... Just to be sure it is triggered or not, and it doesn't.
    • Given the "do something" is just delete the object and that it these objects are never created in the event sheet (they are present on the layout)
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)