Enemy's Health Reset

Just started using Construct 2? Post your questions here

Post » Sat Dec 19, 2015 8:39 am

Hello i'm new on this forum and i've been using Construct 2 for a month. I want to know how to make an "enemy damage health text that resets every time i kill one". I explain better, i created a global value that every time i shoot an enemy by gun, the text score decreases his value by one and it resets when the health's enemy gets the 0 value. The problem is, when i shoot an enemy without killing it, the text doesn't reset and when i try to shoot a new enemy the value continues decreasing..
I hope i explained well and someone can help me ;)
B
2
Posts: 1
Reputation: 152

Post » Sat Dec 19, 2015 9:10 am

*moved to a more appropriate location.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
126
S
29
G
73
Posts: 5,080
Reputation: 51,980

Post » Sat Dec 19, 2015 11:16 am

TheRising0 wrote:Hello i'm new on this forum and i've been using Construct 2 for a month. I want to know how to make an "enemy damage health text that resets every time i kill one". I explain better, i created a global value that every time i shoot an enemy by gun, the text score decreases his value by one and it resets when the health's enemy gets the 0 value. The problem is, when i shoot an enemy without killing it, the text doesn't reset and when i try to shoot a new enemy the value continues decreasing..
I hope i explained well and someone can help me ;)

You cant use a global variable to keep track of enemies health. The reason is that you might have several enemies with different health values.

So to make it work you need as many health values as you have enemies. So making them as global variables are very inefficient, instead you make a variable in the enemy object itself and call that "health" or whatever.

Then when an enemy is hit by a bullet you use this value and display that in the text object that shows the health. Something like this:
Code: Select all
Bullet on collision with Enemy ->
     Enemy.health = Enemy.health - 1
     Text.text = Enemy.health
B
44
S
11
G
2
Posts: 1,181
Reputation: 6,801


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests