Combo System does not accept same input twice

Godot Version

4.4 Stable

Question

Hi there, first time posting here and I’m new to gdscript and Godot in general, so this problem is prolly pretty stupid and easily solvable.

I’m making a combo system for my game where for one attack in a string to be accessed, a previous one must used first. I want to use the same input for the next attack. But for some reason if the input is the same as the first one the next animation will not be played. Here’s the code excerpt:

if Input.is_action_just_pressed("attack1"):
		anim_player.play("Punch-1")
		punch1_motion = true
		punch1_timer.start()

if punch1_motion == true:
	if punch1_timer.time_left > .6:
			pass
	elif punch1_timer.time_left > 0:
		if Input.is_action_just_pressed("attack1"):
			punch2_motion = true
			punch1_motion = false
			anim_player.play("Punch-2")

if punch2_motion == true:
	alt_anim = true
	punch2_timer.start()
if punch2_timer.time_left > .3:
		pass
elif punch2_timer.is_stopped():
	punch2_motion = false

If I change

if Input.is_action_just_pressed("attack1"):
		anim_player.play("Punch-2")

to

if Input.is_action_just_pressed("attack2"):
		anim_player.play("Punch-2")

Where attack2 is RMC instead of LMC then it works, but I want to use the same input.
What exactly am I doing wrong here? I’d appreciate help.

The indenting implies that everything in your code is inside the test for is_action_just_pressed("attack1"), which means when you haven’t just pressed the button none of that code will run.

I’d think everything below line 4 or so in your code above should be outside of the input test block.

if Input.is_action_just_pressed("attack1"):
     if not punch1_motion:
		anim_player.play("Punch-1")
		punch1_motion = true
		punch1_timer.start()
	else:
		if punch1_timer.time_left > .6:
			pass
		elif punch1_timer.time_left > 0:		     
            punch2_motion = true
            anim_player.play("Punch-2")
		    alt_anim = true
		    punch2_timer.start()
if punch2_timer.is_stopped():
	punch2_motion = false
if punch1_motion and not punch2_motion:
   if punch1_timer.is_stopped():
       punch1_motion = false

I think this should theoretically work, though you may need to tweak a bit. You need something to reset the combo, that is why I added the last three lines. I am not by my computer so wasnt able to actually mess around with it.

If I visualized the execution right I think it should allow you to attack1, if you don’t combo last 3 lines will reset so that you can attack1 again. Otherwise when you attack again it should be attack2, once attack2 timer expires it should reset again.

I also eliminated your redundant if punch2_motion == true:, since you know it is true when you set it to true.

Also, your timer.is_stopped check was being done inside the input statement, so it wouldn’t actually activate until you click attack while the timer is stopped. (I am assuming this is in physics_process? Or is it in InputEvent?).

1 Like

Actually, I just realized that I indented everything below line 4 only here in the post.
In the code itself there is no indent, and it still doesn’t work. Sorry about that

Yo, even though I quoted the code wrong like an idiot you still managed to solve the problem, haha.
(btw it was in physics_process like you said)
I didn’t even have to tweak anything. Your code by itself already worked. I’ll use it as reference when writing the code for the other combo strings. Thanks a bunch.

1 Like

Glad I could be a help. You had the bones there to make it work, it was just thinking through the progression of logic. Sometimes we just need another set of eyes.

1 Like