This is my first post in the code.org forum. I made this account to ask a coding question.
I am currently trying to make a fighting game in game lab, and right now I'm working on the basic controls and attacks, however I have an issue.
I'm working on an explosion attack when the Z key is pressed and your MP Is over 100, but im having a problem. I put comment in the code below explaining where the problem is. If anyone has a better version of this code that will work please let me know. (Also I'm really new to Game Lab, I just learned the basics in my CS class.)
if (keyWentDown("z")) {
savemp = mp;
mp = mp - 100;
//checks if mp will be less than 0 if subtracted 100 from its current value
if (mp < 0) {
//sets the mp to the amount you had when you pressed z but mp went less than 0
mp = savemp;
} else {
boom.visible = true;
//turns on the explosion hitbox
boom.setCollider("rectangle", 0, 0);
zactive = 1;
//starts the timer for the attack
var btime = btime + 1;
}
//when btime reaches 100 the attack should stop.
//my problem is that btime is not updating at all
//im getting an error that says 'btime' is used out of scope
//not sure what that means
if (btime >= 100) {
boom.visible = false;
//turns off explosion hitbox
boom.setCollider("rectangle", 5000, 5000);
btime = 0;
}
}