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

Get help using Construct 2

Post » Mon Nov 30, 2015 1:55 pm

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!
B
33
S
6
G
1
Posts: 355
Reputation: 2,850

Post » Mon Nov 30, 2015 2:14 pm

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)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Nov 30, 2015 3:56 pm

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)
B
33
S
6
G
1
Posts: 355
Reputation: 2,850


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 44 guests