Unexpected "Trigger Once" behavior?

Discussion and feedback on Construct 2

Post » Fri May 16, 2014 6:35 am

I'm having trouble understanding why "Trigger Once" is not working as expected in this context (see attachment). I'm not looking for workarounds, I'm simply trying to understand why it's doing this.

The Code
I have an object "Sprite" with a variable called "Color". Every second I destroy all existing "Sprite" objects and then create two new ones - one with Color explicitly set to 0, and the other with Color set to 1. After that, based on the value of Color, I set the animation of each "Sprite" object to either "Color0" or "Color1".

Expected Behavior
Every second, I would expect to see one yellow "Sprite" and one blue "Sprite". This is because the "Color = 1" condition for the newly created sprite has never run in the previous tick. It may have run for a previous object, but not for the newly created one.

Actual Behavior
After the first round of creation, both sprites end up being yellow. This is presumably because "Trigger Once' doesn't care about which object it is firing for, it merely checks to see if the same event happened in a previous tick. But I could be missing something.

Exactly what's going on here? Can someone break it down for me?

Thanks!
You do not have the required permissions to view the files attached to this post.
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053

Post » Fri May 16, 2014 9:49 am

Yeah - trigger once only cares if the condition was true or false last tick. It doesn't matter what objects the condition is true for.

Your event 3, for example, will fire once when there is any Sprite with Color = 1, and then it won't run again until there is at least one tick where there is no Sprite with Color = 1.

In this case there is always a Sprite with Color = 1 so the event never runs again after the first time.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,670

Post » Fri May 16, 2014 10:36 pm

thats right, tirgger once...runs once, and it will run again until there is some kind of change on the variables or coditions....
B
23
S
6
G
3
Posts: 316
Reputation: 3,461


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 4 guests