Sprite instances persist after destroy

Bugs will be moved here once resolved.

Post » Fri Sep 06, 2013 12:41 pm

Hi, manual states that events/actions run in order shown but some actions (Sprite.Destroy) seem to occur only after end of main loop.
(also trying to analyse this I got an oddly similar result when setting a global variable).

Link to .capx file (required!):
https://dl.dropboxusercontent.com/u/15657176/Destroy_Order.capx

Steps to reproduce:
1. Run prog
2. Click on a sprite (sprite is destroyed)

Observed result:
1. Note that Destroyed Sprite UID still appears in For Each Sprite report
2. Note also that although 'Clicked' is set to YES the "BEFORE" (before loop end) report (which is after the click event) does not get shown.

Expected result:
1. Destroyed Sprite UID should not be in For Each report
2. "BEFORE" report should be showing
3. "AFTER" (after loop end) is as expected

Browsers affected:
Chrome: yes
Firefox: ?
Internet Explorer: ?

Operating system & service pack:
Win 7 SP1

Construct 2 version:
r143
B
16
S
4
Posts: 35
Reputation: 2,393

Post » Fri Sep 06, 2013 1:01 pm

Closing: this is in fact by design. Objects are only marked to be destroyed by the 'Destroy' action, and are in fact truly removed only at the end of the next top-level event. This is for two reasons:
1) it's a useful feature: sequences like "Destroy sprite"; "Create explosion at Sprite.X, Sprite.Y" in fact work when it would not if the sprite was truly destroyed immediately
2) the architecture of the engine requires that objects are not truly destroyed mid-event, because it may still be picked by conditions in parent events that still reference it.
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,694

Post » Fri Sep 06, 2013 1:22 pm

Hi,
Suspected as much. However, if this is expected behavior, then surely it should be documented (otherwise I would not have reported it).
I had a good search through the manual and could not find anything explaining this (although I found at least one occurrence of the manual distinctly saying instructions are applied in order, whereas "destroy" is clearly not).

Please could you also suggest why, having set the variable Clicked to YES, the next event that checks if Clicked is YES does not get run.

Thanks for the swift action on this,
RR
B
16
S
4
Posts: 35
Reputation: 2,393

Post » Fri Sep 06, 2013 2:40 pm

Triggers fire outside of the event loop. So when 'On left button clicked' fires, it's not currently running the event sheet - the next tick it will run the event sheet from the top, so the next event that runs after the click event is event 1, not event 7.
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,694

Post » Tue Sep 10, 2013 8:33 am

Thank you.
B
16
S
4
Posts: 35
Reputation: 2,393


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 1 guest