How to create a action queue system?

Godot Version

4.2.1

Question

I’m creating an enemy for a game and having a bit of trouble. The enemy has a weapon and attacks when the player enters the “start attack area” but if the player enters “start area attack shape” in the last frames when enemy isn’t damaging the player, the skeleton won’t attack again and will keep walking forward

So the solution I think will work best is a queue system for the attacks so that when the player enters in the last frames the attack gets queued and starts automatically when the first attack ends.

skeleton attack script:


func _on_start_attack_area_body_entered(body):
	print("yes")
	if body.is_in_group("Player_body"):
		is_attacking = true
		animation_tree["parameters/conditions/is_attacking"] = true
		while animation_tree["parameters/conditions/Dead"] != true:
			await animation_tree.animation_finished
			animation_tree["parameters/conditions/is_attacking"] = false


		#insert queue system here?
		# if body.is_in_group("Player_body") and is_attacking == true:
			#add attack action to queue so that it happens when the first attack is finished
	


func _on_start_attack_area_body_exited(_body):
	is_attacking = false


Any and all help is appreciated

I see you are relying on the Area and the animation to control the attacks. You are getting closer to using the state machine with your current setup.

Research the state machine implementation. This will separate the walking behavior and the attacking behavior so that the skeleton will keep attacking as long as the conditions are met. There are some youtube videos on the subject: https://www.youtube.com/results?search_query=godot+state+machine. Adding an attack state is something like an attack queue where it will repeat it’s attack until it changes back to another state.

Alternatively you could try adding an _on_start_attack_body_exited() function to reset the skeleton state to what it was before the player entered the area.