View Full Version : [AS2] Help with game over script
CollinShoe
10-02-2009, 05:26 PM
I have a maze game with health and when the health reaches 0, it is supposed to go to a game over screen. However, whenever i purposely try to die to see if it works, the health goes from 100 all the way into the negatives. this is the code that i have made on an actionslayer in frame 1.
_root.health = 100;
if (_root.health == 0) {
_root.gotoAndStop(5);
}
Thanks for any help i may get.
Collin
Where do you have the code that reduces the value of the health? And wouldn't it be an obvious solution to test if the health is zero after reducing it? Instead of after assigning it a value of 100?
Also, maybe use <= instead of ==
CollinShoe
10-05-2009, 10:03 PM
i have tried <= and it still didnt solve the problem
this is the code to reduce the health
onClipEvent(enterFrame){
if(this.hitTest(_root.mcMain)){
_root.health -= 4;
}
}
and i dont know how i would be able to test if the value is zero. This is the first thing i have made with actionscript and this is what i came up with.
You are already testing if the value of health is zero. That's not the problem. The problem is that you are testing it right after setting it to 100, rather than after you reduced it by 4.
CollinShoe
10-05-2009, 11:06 PM
so how would i fix that?
Look through the code you've posted. There are two places where you change the value of health. Right now, your test is after one of them and it should be after the other.
CollinShoe
10-05-2009, 11:11 PM
Thank you for your help it works now.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.