R89 Destroyed Sprite still counted & ForEach Wrong

Bugs will be moved here once resolved.

Post » Fri May 11, 2012 10:54 am

Not sure if this is intended to work this way, but i hope not.

capx:
http://dl.dropbox.com/u/39382262/BUGS/DestroyForEachBug.capx

simple Event Sheet:


Result:



Expected Result:
- Circle.Count = 4
- "For Each" loop only run 4 times and only for the alive object (skipping the destroyed object)




B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Fri May 11, 2012 11:11 am

This is sort of by design... "Destroy" means "flag to be destroyed at the end of the event sheet". This is because people commonly write events like

Destroy Sprite
Create explosion at Sprite.X, Sprite.Y

If the Sprite was really destroyed, the explosion would have nowhere to be created because the Sprite doesn't have an X or Y co-ordinate any more. I could fix the two cases you've shown, but the object would still actually exist until the end of the event sheet, which might just make for some more confusing cases.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Fri May 11, 2012 11:27 am

Ah i see that's good to know, thanks Ashley.

I thought a good event sheet user should do:
- create explosion first
- destroy the sprite

or

- save X & Y of the sprite
- destroy sprite
- create explosion on X & Y

but oh well, at least i know how it works now :D
I should be more careful when using Count, For Each & Picking using IID now
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Fri May 11, 2012 7:08 pm

Ashley,

After thinking about this, I find myself relying a lot on Object Count & For Each,
and it would be awesome if i can get an accurate count of the object that still alive.

so if it's not too much to ask can i request something like:

1. Object.CountAlive = return a correct number of object that's not destroyed

2. Condition Object is still alive / Object.AliveFlag
so i can still do something like this when i need to:

[code]
For each CIRCLE
---CIRCLE is still alive
------do something on CIRCLE
[/code]

Thanks a lot :D
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Fri May 11, 2012 8:01 pm

@Ashley - Could it work instead like in CC where objects are fully created or destroyed at the next base event instead of at the end of the event sheet?
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Fri May 11, 2012 8:21 pm

[QUOTE=Arima] @Ashley - Could it work instead like in CC where objects are fully created or destroyed at the next base event instead of at the end of the event sheet?[/QUOTE]

This idea actually would works great too....
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Fri May 11, 2012 11:27 pm

use local variable. first set it to sprite.count then subtract 1 every time you destroy sprite. in the end you'll have number of spritrs left in the same tick.
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Sat May 12, 2012 1:03 am

[QUOTE=ranma] use local variable. first set it to sprite.count then subtract 1 every time you destroy sprite. in the end you'll have number of spritrs left in the same tick.[/QUOTE]

but... but... but... it will be so much easier if Ashley is the one
who have to do all the work for us.




just kidding...


yeah I can always do as your suggested ranma,
also i can just slap a variable isAlive to the object on my own,
and set it FALSE when the object is destroyed so that when i need to do a FOR EACH (i can just skip the one that is not alive)


ok then... case solved, move along..... nothing to see here
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Thu May 17, 2012 2:56 pm

I've changed the next build to clean up destroyed instances between top-level events, like Classic does. Hopefully that's a good enough fix? It's really hard in the engine to clean it up in a subevent, I don't think we can support that.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Thu May 17, 2012 4:44 pm

Awesome! I found it really useful in CC, so thanks @Ashley!
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Next

Return to Closed bugs

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests