R89 Destroyed Sprite still counted & ForEach Wrong

0 favourites
  • 14 posts
From the Asset Store
An educational game for counting pictures. An easy to use template for developers to build larger games
  • 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:

    <img src="http://i48.tinypic.com/aexfnm.jpg" border="0">

    Result:

    <img src="http://i49.tinypic.com/9a0mpw.jpg" border="0">

    Expected Result:

    • Circle.Count = 4
    • "For Each" loop only run 4 times and only for the alive object (skipping the destroyed object)
  • 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.

  • 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 <img src="smileys/smiley23.gif" border="0" align="middle" />

  • 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:

    For each CIRCLE
    ---CIRCLE is still alive
    ------do something on CIRCLE
    

    Thanks a lot :D

  • 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?

  • 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?

    This idea actually would works great too.... <img src="smileys/smiley20.gif" border="0" align="middle" />

  • 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.

  • 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.

    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 <img src="smileys/smiley2.gif" border="0" align="middle" />

  • 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.

  • Awesome! I found it really useful in CC, so thanks Ashley!

  • Um..

    How will that work with On create, and on destroy?

  • newt - they won't be affected. The only thing is whether or not 'for each' still iterates it, and the object count, IIRC.

  • Ashley, you're the best !! <img src="smileys/smiley41.gif" border="0" align="middle" />

    btw just wondering...

    1. When you say "Top-level events" does it means :

    Event 1
    --Event 2
    --Event 3
    ----Event 4
    ----Event 5
    --Event 6
    --Event 7
    Event 8
    Event 9
    

    If i destroy object at Event 4 does the change gonna be reflected on :

    Event 5, 6, 7, 8, 9

    OR only

    Event 8, 9

    2. Does the change also reflected on object IID ?

    or object IID will stay the same until end of event sheet. (when object got destroyed for real)

    So in the case of my circle example earlier:

    Circle IID will be 0, 1, 2, 3

    OR

    it will stay as 0, 1, 4, 5 ? (until end of event sheet)

    Thanks again Ashley.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Potato - it will be updated in event 8 since it's the next top-level event (as in, not a subevent to anything else). That's also when the IIDs are updated, because the object still actually exists until then.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)