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;
}
}

    Edit- Ignore this one. I needed to make it more clear

    Sorry for so many posts lol😅 but this will be my last until you respond. Maby a project link so I can look? Also if u send a link (if u want u can send it in a pm) can I remix it?

      heisenburg I can’t really look right now, I’m currently on my school iPad, but I know it’s set as a variable

      ackvonhuelio im not progamming on ipad, i was just replying to people on ipad, im on my computer now

      So basically, i just got help from chatgpt to make my code work, i guess i dont need this thread anymore

      I know the issue. btime never counts back down from 1 causing the btime to never restart. if you did want it to restart, then you would need to press z 100 times.

        2 months later

        where has bro appeared from to leave this utterly misplaced comment

        Chat