0 Favourites

How do I use For Each?

  • Has anyone actually figured out how this condition works? I know you use it for multiple instances of the same sprite, but it always seems to require hours of headaches moving "for each" to different events to see its effects.

    And even then, I'm still able to figure out a bug (ie. if you DONT kill the first enemy and move past him, the second one wont do what it's supposed to)

    All I've figured out is that when picking instances via instance variables/booleans, anytime you use Else, it disables the picking. Can anyone shed some insight on this? Thanks.

  • ome6a1717 - I usually use "For Each" with object families.

  • after a lot of headaches i found a reply post from ashley that explained the situation.

    all system conditions do not pick instances.(compare,trigger once ,else etc) so you need to add a " for each"

    everything else, he has programmed it to automatically pick instances. it has a build in "for each" so no need to add one.

    hope i cleared things up

  • The for each conditions is something that can be used when you are using a condition that does not pick any object (for exemple: compare two values) so you can pick all of them at once.

    The Else does not pick any object (cf. manual), so it will mostly compare for the oldest instance by default, but I think you can do without it in most cases (compare the other value of a boolean for exemple, etc..), I always try to make it that C2 take care of the picking.

    in fact, I use it only when it happens that I need it, which does rarely for me.

  • Roccinio, right - thats how I've been using my for each's, but I seem to find bugs every time.

    For instance, one of the issues I'm having right now:

    Player.Y < Enemy.InstanceVariable

    For Each Sprite

    DO THIS

    Else

    Player.Y >Enemy.InstanceVariable

    For Each Enemy

    DO THIS

    Since it's not actually picking each individual enemy instance, it requires a for each.

  • Aphrodite - I completely understand that. That's why I'm baffled what I'm doing isn't working properly.

    Does it matter when the for each is taken into account? Should it be a sub-event of the instance pick, or with the instance pick event; above or below?

  • Aphrodite - I completely understand that. That's why I'm baffled what I'm doing isn't working properly.

    Does it matter when the for each is taken into account? Should it be a sub-event of the instance pick, or with the instance pick event; above or below?

    it matters, In your case I think you have to use it before the comparaison

  • yes use for each before and then add subevent the rest

    for each "sprite"

    .................compare 2 values------------------------------->then do something

  • Arima - nice tutorial. It helped a bit, but I'm still having issues when multiple enemies are on screen (however all of your advice helped when you DONT kill an enemy and get to the next one)

    Hm. As far as I can tell, I'm doing this right. Can anyone point out any visible issues?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Yeah, else does no picking at all, nor does it remember or invert the picking from the event above it. I don't think you should use any of the else conditions in that screenshot at all. Instead of:

    Event 1: X is less than player.x

    Event 2: Else

    Use:

    Event 1: X is less than player.x

    Event 2: X is greater or equal to player.x

  • Arima - actually not using else breaks most of the events. This is what I mean - it only seems to work for certain events.

  • Hmm, I'm not sure. I guess I would need a capx to investigate further.

  • Slight update - its seeming to be that booleans do not pick instances, either. I didn't realize, but the event "MassiveScorpion is on-screen" was actually doing the picking; this is why it seemed to be working when multiple enemies weren't on the screen. The second I got rid of that, all of the events under them no longer worked.

    I'm totally confused, and not just in this specific instance, on instance picking in general.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,137
karshinkoff's avatar
karshinkoff
Unread hot topic
56 4,732
MPPlantOfficial's avatar
MPPlantOfficial
Unread hot topic
76 9,273
Pandadoor's avatar
Pandadoor