Events executed in the wrong order

Bugs will be moved here once resolved.

Post » Wed Mar 16, 2016 8:05 pm

Message: Estecka can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Problem Description
Picking two events modifying one variable, the changes from the first to come will be carried after the second is executed. The changes from the second to come will not be kept outside of its own scope.

Attach a Capx
http://sta.sh/010tefj7gcwj
Image

Description of Capx
Spite haz boolean.
When boolean True, sprite destroyed.

Two times in the project, the boolean value is changed:
- A first time with no condition: the boolean is set to false.
- A second time, on click, it is set to True.
Afterward, the boolean is checked, and the sprite i or isn't destroyed.

Since the boolean is set to True AFTER being set to False, it should still be considered True afterward by the following events.
It is not.

Steps to Reproduce Bug
  • Disable Event 1 and run the project. On click, sprite is destroyed.
  • Enable Event 1 and rerun the project. The sprite won't be destroyed anymore.
  • Make Event 3 a subevent of Event 2. The sprite will be destroyed again

Observed Result
The action of Event 1 will be carried after Event 2, despite Event 2 supposedly cancelling it.

Expected Result
Event 2 overwrites Event 1 's changes once and for all.

Affected Browsers
  • Chrome: (YES)
  • FireFox: (YES)

Operating System and Service Pack
Windows 8.1 / windows 7

Construct 2 Version ID
r221
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Wed Mar 16, 2016 8:17 pm

The trigger "on click" is run when the mouse clicks, it's not run top down.
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971

Post » Wed Mar 16, 2016 9:15 pm

Wait...
But then when are triggers executed in the code? In-between ticks? How do you control that ?
I don't understand why. What makes it so it was intended not to work the same way as: ?
Image
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Wed Mar 16, 2016 10:25 pm

Triggers (the events with green arrows) run in the order defined in the event sheet but before regular events. If you imagine all triggers at the top of the event sheet - that's how it works.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Thu Mar 17, 2016 1:41 pm

Event number 1 is pretty much "Every Tick", and as @ramones mentioned above, the boolean is set to false before checking if it is true.
B
29
S
14
G
6
Posts: 160
Reputation: 5,752

Post » Thu Mar 17, 2016 4:42 pm

Yeah, I've checked the manual and understand how these triggers are supposed to work, but I still don't understand is why they need to work this way.
I mean, code not executed in writing order, I'm falling off my basics here. Am I the only one to question this?
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Thu Mar 17, 2016 5:04 pm

Basically any trigger except "on collision" (which is run in place) can be run inspite of its location on the event sheet. Simple things like "on start of layout" and "on function" are example where you wouldn't want it to run when the event sheet gets to them. Another reason is if the condition is triggered multiple times. With mouse button is down that event would run only once per frame, wereas on click would run for every click. Now for the mouse this won't really happen since you can't click multiple times in 1/60th of a second. It is possible with something like on any key pressed.
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971

Post » Thu Mar 17, 2016 6:52 pm

=> "A single trigger can be run multiple times per tick"
Oh, I never actually considered that. I think I'm starting to see the nuance here.
Thanks for the information.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Tue Mar 22, 2016 3:33 pm

Closing as not a bug - the fact triggers run outside of the normal event flow is documented.
Scirra Founder
B
395
S
233
G
88
Posts: 24,376
Reputation: 193,852


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 3 guests