How do I put global variable for a single obj

Get help using Construct 2

Post » Wed Apr 08, 2015 11:05 am

Hi,
I made some tank bots and their health is a global variable (=30)
if bullet on collision with bot , subtract 10 from bothealth.
But if I kill a bot and another had respawn the bouth bots are killed.
How must I make to kill just the hitted bot?
have I made something wrong?
Thanks.
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Wed Apr 08, 2015 1:21 pm

You need to use an instance variable, not a global variable. Instance variables are set on and only affect an object. Global variables are non-specific, hence the name global. Each tank will have an instance variable called health with a starting value of 30. Then, only the tank whose variable reaches 0 will be destroyed.
B
39
S
12
G
11
Posts: 331
Reputation: 7,727

Post » Wed Apr 08, 2015 6:28 pm

@FragFather
Thank you
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Wed Apr 08, 2015 7:48 pm

@FragFather
Have you any idea of this;
I have a tank and a turret on it , differents sprites and when I distroy the tank the turret stays and if i do this " tank on destroi -> destroy turret" it destrois all tank turrets.
Any idea how to fix this?
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Wed Apr 08, 2015 8:52 pm

Put the tank and turret in a container.

https://www.scirra.com/manual/150/containers

or add a turret is nearest condition.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to How do I....?

Who is online

Users browsing this forum: Blendi1223, Darknessed, Yahoo [Bot] and 36 guests