ForumsProgramming ForumFlash As2 Prevent from holding down key

3 4699
DapwnageG
offline
DapwnageG
205 posts
Nomad

I am working on a game, but there is a problem that when the player holds down the attack button, he continuously attacks until you release the button. What script do you use to make it so they only attack once when you hold it down?

  • 3 Replies
Darkroot
offline
Darkroot
2,763 posts
Peasant

A timer and create the delay you want. Though you'll have to do some extra coding so they can't just spam the button instead.

DapwnageG
offline
DapwnageG
205 posts
Nomad

I actually found a better way, because the players are supposed to spam the button, but not hold it down.

if(Key.isDown(Key.SPACE)){
if(AttackVar == false){
this.gotoAndStop(3);
attack = true;
AttackVar = true;
}
attackButton = true;
}else{
attackButton = false;
}
if(attackButton = false && attack = false){
AttackVar = false;
}


But I think I have an unnecessary amount of variables. The script works though.

DapwnageG
offline
DapwnageG
205 posts
Nomad

Oh and also:
if(_currentframe == 1){
attack = false;
}

because once the attack animation ends the player goes to frame 1.

Showing 1-3 of 3