'For each' broken?

This forum is currently in read-only mode.
  • Okay, maybe I misunderstand how this works...

    I want each enemy to have a little healthbar. So my event looks like:

    For each enemy -> Spawn monster_healthbar.

    Now, if my logic is correct, that means that for each enemy Construct would spawn a healthbar. So if there are 5 enemies on the screen, I'd have 5 healthbars, right?

    The problem is that Construct doesn't do that. It just starts to spawn stuff and keeps spawning a healthbar for every single tick.

    Is my logic just wrong or is that event broken at the moment? I'm still on Construct 99.72 btw.

  • I actually had a similar problem recently, the solution was to either create the health bars when the enemies were spawned, or if they are already spawned when your layout starts, you go:

    On start of layout:

    For each enemy -> Spawn health bar

    put for each enemy as a sub event.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I want each enemy to have a little healthbar. So my event looks like:

    For each enemy -> Spawn monster_healthbar.

    I'm have no hand on construct right now. But from my mind: Isn't 'for each enemy' true every tick? If you just want to happen this once you have to further limit it, for example for each enemy that doesn't have a healthbar yet, or something.

  • Isn't 'for each enemy' true every tick?

    Yes it is. You need to trigger it just one time.

  • Why not just use containers if you want each enemy to have a health bar?

  • Why not just use containers if you want each enemy to have a health bar?

    --This

    You will (probably) need a for each without a trigger to set the position, and the health bar will be created when the enemy object is. If you don't want it visible until it takes damage just set it to be invisible, and use a condition that compares a variable.

  • I think I know where this is going, and I've been there.

    You want each enemy to have a health bar, but you've placed them in the IDE so containers aren't really useful since you can't associate any healthbar instance to any enemies, also placing healthbars in the IDE is kind of overkill.

    When I had that issue, I used the enemies as "markers". I had one healthbar instance, with "Destroy on startup" attribute. I had placed enemies at their locations, then, On Layout Start, I would for each enemy sprite destroy it and then create a new one at the same location. Since I had healthbars in a container with the enemy sprites, they would both spawn and become associated.

    Tangly paragraph that last one. Let me know if its unreadable.

  • Thanks all you guys for the suggestions, madsters solution soundsl like win to me.

    I'll try it out this evening and update this thread later on.

  • Madster FTW!

    I added the healthbar into a container with the sprite, destroyed both on start and just had the enemy respawn - because the helathbar is in a container it spawns with the enemy, problem solved

  • Wooo I was useful!

    *celebrates*

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