Same variable name for all sprites

Get help using Construct 2

Post » Mon Nov 05, 2012 6:38 pm

I intend to use a different enemies with the same local variable (numLife). I would like to check the life bar of these sprites at sigle time (eg. enemyObject.numLife) . How can I do this?

Thanks
B
65
S
13
G
2
Posts: 969
Reputation: 6,732

Post » Mon Nov 05, 2012 7:23 pm

Yeah you've got it correct.

the variable will be objectname.varname

so for example

system every tick -> No action
(sub event) system compare instance variable enemy.numlife <1 --> destroy

now any time a enemies life = 0 it will get destroyed.
B
50
S
21
G
8
Posts: 844
Reputation: 10,299

Post » Mon Nov 05, 2012 7:38 pm


Very clear. Thank you, @justifun
B
65
S
13
G
2
Posts: 969
Reputation: 6,732

Post » Mon Nov 05, 2012 7:45 pm

One problem: I didnt see this variable in the comparable variables option of System event. Maybe because its a local variable?RenatoB2012-11-05 19:47:31
B
65
S
13
G
2
Posts: 969
Reputation: 6,732

Post » Mon Nov 05, 2012 11:43 pm

That's because the variable comparison for a sprites instance variable is under the sprite, not the system.

Click on the sprite, and look for the "Instance Variable" heading. you will find the comparison there.
B
200
S
51
G
30
Posts: 896
Reputation: 36,494

Post » Tue Nov 06, 2012 10:18 am

Hi @Paradox,

This I already knew. The problem is that this way I have to create the command for each sprite and I would like to create a general command to verify all objects at once
B
65
S
13
G
2
Posts: 969
Reputation: 6,732

Post » Tue Nov 06, 2012 3:37 pm

So you want to check them all at once?, in that case put your "check" into a for each (ordered) loop.
B
50
S
21
G
8
Posts: 844
Reputation: 10,299

Post » Tue Nov 06, 2012 6:28 pm

If all of them are picked, (you didn't filter any out with events,) it should still work on all of them. "For each" is assumed.
I would be 100% sure of that if I hadn't just read Justifun's suggestion.

Edit: I see, you meant you do have some filtered? It works the same way as a system version would, they both act on what is picked. (all top events start with everything picked, and you filter down to the ones you want to work on. However you can use "Pick All" to reset the picking list.)Paradox2012-11-06 18:34:11
B
200
S
51
G
30
Posts: 896
Reputation: 36,494

Post » Tue Nov 06, 2012 6:44 pm

I think what you want are families. They're basically a group of objects that acts like an object itself, meaning you can also give the family a variable, resulting in all of the group's objects getting that variable as well.

That way you can check the variable for a bunch of objects with one condition.Arima2012-11-06 18:45:22
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Tue Nov 06, 2012 7:08 pm

Thanks @justifun and @paradox. Ill try to implement the justifun suggestion

Youre right, @arima. But its ony available in personal/commercial version. Ill intend to buy the C2 very soon.
B
65
S
13
G
2
Posts: 969
Reputation: 6,732

Next

Return to How do I....?

Who is online

Users browsing this forum: austinblackbelt, Yahoo [Bot] and 23 guests