Global variable problem

Get help using Construct 2

Post » Sun Aug 05, 2012 6:31 pm

Hello guys,

I have little problem. I am absolutely beginner so I am sorry if this sounds stupid.

I have a global variable called enemies_number. The value of it is set to 5.

And then when I hit some enemies I do like: enemies_number-1 and in conditions I also have this:

What I am trying to do is that until enemies_number is not 0 I can generate this "sprite 4" every 8 seconds. But what happened is that when my enemies_number is 0 sprite4 is still spawning even it should not. How come?

Thank youMichal112012-08-05 18:32:18
Posts: 45
Reputation: 1,168

Post » Sun Aug 05, 2012 6:53 pm

It's because of how events work.
Event 10 (your "Every 8 seconds" count) is a sub event to event 9 (the blank event) which is true every tick.
You should rather put in event 8 the conditions :
System: Every 8 seconds
System: enemies_number =not 0

and put the actions of event 10 in event 8.

This way, every 8 seconds C2 would test if "enemies_number" is different than 0, and if it is, it will spawn a new sprite.
Else, the condition being false, the actions wouldn't be executed.

Also you don't necessarily need a global variable to keep count of the instances number.

Considering your object type is a sprite named "Enemy", you could instead of "System: enemies_number =not 0" having a "System: Compare two values" condition, its first field being "Enemy.count" not equal 0.Kyatric2012-08-05 18:54:54
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Posts: 7,381
Reputation: 73,838

Return to How do I....?

Who is online

Users browsing this forum: A01214706 and 6 guests