For Each Object

  • Hi guys,

    I'm trying to get the For Each Object event working but I am not having much success... Here is a snippet of some test code.

    <img src="http://dl.dropbox.com/u/40935009/snippet.png" border="0" />

    1. I create five sprites on start of layout, then display the sprite.count which displays 5. This is correct.

    2. I then added a sub event to destroy them. It only destroys 1 sprite. The count is then displayed as 4, which is correct.

    The For Each doesn't seem to iterate through all the objects. Am I misunderstanding something?

    Sim

  • Make another event for the "For Each" statement. I think the fact that you are creating new objects in the parent event is messing up the picking.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The 'create object' action sets the picked objects to just the created object.

    Sub-events inherit the parent event's picked objects, so the subevent inherits a single Sprite (the last created one).

    For-each only iterates the currently picked objects, so it runs once for that last created sprite. (In this case you don't need a for-each, it has no effect - actions naturally run "for each" picked object. You only need a for-each when this built-in behavior does not do what you want.)

    To fix it, make a second 'start of layout' event that just has 'wait 5 seconds' then 'destroy Sprite'. That event has a blank slate for picked objects, so all sprites are destroyed.

  • HI Ashley and Cow_trix,

    Thanks for the help. I need to rethink my approach when implementing such functionality with Construct 2. I have much to learn...

    Cheers

    Simon

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