For Each + Trigger Once

Get help using Construct 2

Post » Mon Mar 11, 2013 6:02 pm

Hi guys
I want to do the following:


For each Sprite when instance variable aaa becomes 0, to add 1 to global variable zzz only once.
Any thoughts how i should do it?
Thanks in advance.
B
12
S
3
G
1
Posts: 120
Reputation: 1,829

Post » Mon Mar 11, 2013 6:07 pm

I think it will be ok if you remove the Trigger once condition. And put the add 1 to zzz as an action in the For each Sprite condition.

I'm sure that will give you the result you're looking for.
B
20
S
5
G
3
Posts: 53
Reputation: 3,310

Post » Mon Mar 11, 2013 6:27 pm

The problem is i want to add 1 to zz only once. If i put it with For Each event it starts continuously adding.
B
12
S
3
G
1
Posts: 120
Reputation: 1,829

Post » Mon Mar 11, 2013 6:42 pm

Store the last value of aaa in another variable then you can check if aaa = 0 and last_aaa not = aaa, add 1 to zzz. At the end of the event sheet, set last_aaa to aaa.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Mon Mar 11, 2013 7:14 pm

Drop the for each, and change the instance variable back to its original state in the same event.

+on your trigger, set instance variable to 1

+instance variable =1, system add 1 to global variable, instance set variable back to 0

If you need to keep the instance from changing again, add a condition for that.

Here is a tut on how to use for each properly.
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Mon Mar 11, 2013 7:15 pm

Add 1 to zzz
Set aaa to -1
Maby this will help...
B
9
S
3
G
3
Posts: 36
Reputation: 2,433

Post » Mon Mar 11, 2013 7:46 pm

Thanks for help guys. I thought it can be done only with For Each expression but it seems i was all wrong (not my first time :). Ill defenetly check the tutorial newt, thanks.
B
12
S
3
G
1
Posts: 120
Reputation: 1,829


Return to How do I....?

Who is online

Users browsing this forum: selaus and 0 guests