'For each' broken?

For questions about using Classic.

Post » Tue Feb 16, 2010 8:12 am

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.
B
6
S
2
G
3
Posts: 520
Reputation: 2,690

Post » Tue Feb 16, 2010 8:16 am

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.
B
7
S
2
G
4
Posts: 164
Reputation: 2,418

Post » Tue Feb 16, 2010 9:26 am

[quote="thomasmahler":3lb1jnyw]I want each enemy to have a little healthbar. So my event looks like:

For each enemy -> Spawn monster_healthbar.[/quote:3lb1jnyw]
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.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Feb 16, 2010 9:36 am

[quote="tulamide":1945atvy]Isn't 'for each enemy' true every tick?[/quote:1945atvy]

Yes it is. You need to trigger it just one time.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Feb 16, 2010 1:43 pm

Why not just use containers if you want each enemy to have a health bar?
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Tue Feb 16, 2010 4:33 pm

[quote="Aeal5566":vmy3f4yf]Why not just use containers if you want each enemy to have a health bar?[/quote:vmy3f4yf]<--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.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Tue Feb 16, 2010 7:15 pm

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.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Tue Feb 16, 2010 8:05 pm

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.
B
6
S
2
G
3
Posts: 520
Reputation: 2,690

Post » Wed Feb 17, 2010 6:15 am

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 :)
B
6
S
2
G
3
Posts: 520
Reputation: 2,690

Post » Fri Feb 19, 2010 5:20 am

Wooo I was useful!

*celebrates*
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests