Originally Posted By: h34dl4g
When the whole animation is over, you can press another time on "q" to get a new attack.


Hey, try something like:
Code:
#define anim_idle 0
#define anim_attack 1
action guard_with_pointer(){
	guard1 = my; //needed?
	
	var anim = anim_idle;
	var anim_percent = 0;
	var health = 100;
	var able_keyQ = true; //flag for identifying if 'q' is needed to be pressed
	
	while(me){ //change to me to prevent crashes when me doesn't exist
		if(health > 0){ //dont do anything if dead
			switch(anim){
				case anim_idle:
					if(able_keyQ){ //if accepting 'q'
						if(key_q){
							anim = anim_attack;
							able_keyQ = false;
						}
					}else{
						if(!key_q){
							able_keyQ = true;
						}
					}
				break;
				
				case anim_attack:
					anim_percent += 3 * time_step;
					if(anim_percent >= 100){ //if finished attack
						anim = anim_idle;
					}else{
						ent_animate(my, "attack", attack_percentage, ANM_CYCLE);
					}
				break;
			}
		}
		wait(1);
	}
}



though without wanting to do everything inside 1 loop, i'd agree with Esper and have a seperate function for checking, especially if you're already creating global entities
Code:
action guard_with_pointer(){
	//... blah!
}

change_state(){
	if(guard1){ //make sure he exists
		if(guard.anim == anim_idle){
			guard1.anim = anim_attack;
		}
	}
}

void main(){
//...
on_q = change_state;
}


hope these help
*untested!*