Why is this error? Error: calling method from signal 'timeout'

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dion.cq

Does anybody know why this error is happening:

E 0:00:05.712 emit_signal: Error calling method from signal
‘timeout’: ‘KinematicBody(Player.gd)::recoil’: Method expected 1
arguments, but called with 0… <C++ Source> core/object.cpp:1242 @
emit_signal()

This is the code which is probably the problem:

func weapon_functions(delta):
# Call recoil every time the shoot animation is played
var timer = Timer.new()
if player_shooting == true:
	timer.set_wait_time(current_weapon_recoil_time)
	timer.set_one_shot(false)
	timer.connect("timeout", self, "recoil")
	add_child(timer)
	timer.start()
else:
	timer.stop()


recoil(delta)

Is the code suppose to be this?

func recoil(delta):
    pass

Ertain | 2022-10-07 17:35

:bust_in_silhouette: Reply From: jgodfrey

Your recoil function is expecting an argument to be passed into it (delta). However, that’s not being passed in due to the way you’ve wired the timeout function. If you don’t need the delta argument, remove it from the function definition. If you do need it, then pass it in like:

timer.connect("timeout", self, "recoil", [delta])

Thank you :smiley:

dion.cq | 2022-11-30 22:51