I can't figure out how to make my character do a combo

Godot4.7

I don’t know how to do a combo attack.

I’ve been trying to add a combo system to my top down perspective game for over a week now and I’m at my wits end. Every guide or forum post that I’ve found only seem to edge me to a solution that i cant reach and it’s driving me mad.

I’d really appreciate some help here, I tried to trim down the code into only the relevant portions. This is an extended script based on an earlier instance of the player character if that helps, though the earlier instance can only use 1 attack and this is supposed to be an upgrade that the player gets halfway through the game. I’m also using an AnimationTree as a state machine and i have no clue if that’s good or not.

func _physics_process(delta: float) -> void:
	var state = playback.get_current_node()
	match state:
		"MoveState": move_state(delta)
		"Attack1": pass

func move_state(_delta: float) -> void:
	input_vector = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
	if input_vector != Vector2.ZERO:
		last_input_vector = input_vector
		var direction_vector: = Vector2(input_vector.x, -input_vector.y)
		update_blend_position(direction_vector)
	
	if Input.is_action_just_pressed("Attack"):
		playback.travel("Attack1")
		combo_timer.start()
		if Input.is_action_just_pressed("Attack") && combo_timer.is_stopped():
			combo_timer.start()
			playback.travel("Attack2")
			if Input.is_action_just_pressed("Attack") && combo_timer.is_stopped():
				combo_timer.start()
				playback.travel("Attack3")
				if Input.is_action_just_pressed("Attack") && combo_timer.is_stopped():
					combo_timer.start()
					playback.travel("Attack4")

func update_blend_position(direction_vector: Vector2) -> void:
	animation_tree.set("parameters/StateMachine/MoveState/MoveState/blend_position", direction_vector)
	animation_tree.set("parameters/StateMachine/MoveState/StandState/blend_position", direction_vector)
	animation_tree.set("parameters/StateMachine/Attack1/blend_position", direction_vector)
	animation_tree.set("parameters/StateMachine/Attack2/blend_position", direction_vector)
	animation_tree.set("parameters/StateMachine/Attack3/blend_position", direction_vector)
	animation_tree.set("parameters/StateMachine/Attack4/blend_position", direction_vector)

Remember that code executes all at once, walk through it line by line and everything there happens on the same frame. If the first if Input.is_action_just_pressed passes, then all the ones below it will pass too. On the next frame it has to start from the top again, so it will only travel to “Attack1”. You need another variable to keep track of the combo’s state, which “Attack%d” it’s traveled to last.

Thanks! It still took me awhile but i figured it out with help from your comment. The funny part is that the moment i did it, i found a video from a channel called AntiDev that figured out the solution i came up with seven years ago, lol