View Full Version : Whats wrong with this AS
WarrOrange
January 20th, 2004, 07:29 PM
Ok i was making code so when the enemies hp is 0 or less than it would goto and play the win frame and if your hp is = or less than 0 it would play the frame "lose". I have no idea why this isnt working but hopefully one of you kirupians can help me out
if (_root.enemyhp < 0)
{
gotoAndPlay("win");
}
if (_root.hp < 0)
{
gotoAndPlay("lose");
}
Digigamer
January 20th, 2004, 07:38 PM
if enemyhp and hp are variables you shouldn't need the _root. Try gettinging rid of that and see if it works.
claudio
January 20th, 2004, 08:40 PM
The reason it isnt working is because the statement is only checked once when the movie starts. Use setInterval, onEnterFrame handler or object.watch to constantly check for that condition.
WarrOrange
January 21st, 2004, 05:05 PM
alright i edited it a lil and it still doesnt work.. here we go check it out
_root.enemyhp = Math.floor(Math.random() * (70 - 30)) + 30;
if (_root.enemyhp < 0)
{
gotoAndPlay("win");
}
if (_root.hp < 0)
{
gotoAndPlay("lose");
}
enemyhp.watch();
claudio
January 21st, 2004, 07:06 PM
function checkHp(prop, oldval, newval, label) {
if (newval<0) {
gotoAndPlay(label);
this.unwatch(prop);
}
return newval;
}
this.watch("hp", checkHp, "lose");
this.watch("enemyhp", checkHp, "win");
REEFˇ
January 21st, 2004, 08:59 PM
// New Function:
function healthPoints() {
// If our HP is more than 0 and the enemies' HP is 0 or less:
if (hp > 0 && enemyhp <= 0) {
// Go to and play the win frame:
gotoAndPlay("win");
// Else if our HP is 0 or less and the enemies' HP is more than 0:
} else if (hp <= 0 && enemyhp > 0) {
// Go to and play the lose frame:
gotoAndPlay("lose");
}
}
// Run function rapidly:
setInterval(healthPoints, 0);This code prevents a tie, making it impossible to have 0 and 0. As soon as one has 0 and the other is greater, it goes to the resulting frame.
- Sharif ;)
WarrOrange
January 22nd, 2004, 08:07 AM
thanks sharif and claudio!
claudio
January 22nd, 2004, 11:54 AM
welcome :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.