Event questions

Get help using Construct 2

Post » Sun Jan 15, 2012 3:24 am

[QUOTE=Yann] Normal, you set Respawn to 0 every tick o.o[/QUOTE]
But event sheets run from top to bottom, so it should only be 0 at the very end of the tick.

This is the pseudo-code of what I had in mind:

foreach monster:
Subtract dt from monster.Health

foreach monster:
if monster.alive & monster.Health<=0 :
    destroy monster
    increase RespawnCounter by 1

Repeat RespawnCounter times:
System create new monster

System Set RespawnCounter=0
    
So first we decrease the lifetime counter for all monsters. Then pick the ones that have lost all their health (and have their "Alive" flag set) and kill those. For everyone that got killed increment global variable so we can respawn them later. Next run a loop and create a bunch of new monsters. Once we are done with that reset respawncounter to 0 so no more new monster appear.

I am completely aware of the fact that you can get the same behavior with a dozen different conditions/actions. My question is: why is the example I posted in the OP not behaving as outlined in the pseudo code above? The monsters all disappear but only 1 new monster gets spawned. It's as if the Repeat loop only runs once.
B
12
S
3
G
3
Posts: 73
Reputation: 2,647

Post » Sun Jan 15, 2012 3:36 am

probably because they all disappeared at the same tick.

So if you don't use a foreach, you will trigger the add 1 to RespawnCounter only one time (even if all the monster are destroyed, it's like an internal loop)

If you use the foreach, each monster will be taken into account and RespawnCounter will be increased for each monster that have their health <= 0
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sun Jan 15, 2012 5:02 am

Yep, they all disappeared at the same tick.

The C2 System manual states: [quote]For Each is commonly mis-used or used redundantly - actions already apply for each instance picked by conditions, so it often is simply not needed.[/quote]That's why I tried to remove the ForEach because it sounds like C2 should already be iterating over each instance that disappeared during that tick without me having to run a ForEach condition on it.

For reference here's the bad code again:


B
12
S
3
G
3
Posts: 73
Reputation: 2,647

Post » Sun Jan 15, 2012 5:47 am

Well if you send me the capx I can show you how I would implement what you ask. 'cause you know... it's easier if you have a capx ready :D
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests