Error: Signal 'timeout' is already connected to given method?

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

So I’m making an RPG and I have 5 player characters, each with their own scrolling container on the HUD. What I’m trying to do is check if the HBox inside the scrolling containers has more than 15 objects (not counting the scroll_h and the scroll_v) and scroll to the end, wait a second, and scroll back to the beginning, if that makes sense. I managed to code the first one perfectly, but the second one doesn’t work and gives me this error:

connect: Signal ‘timeout’ is already connected to given method ‘_on_p2Timer1_timeout’ in that object.

I’m not sure what is going on, someone help? Here is my code:

func scrollBuffs():
#Player 1 Scroll Buffs
if buffsP1.get_children().size() <= 17:
	p1ShouldScroll = false
	p1Scrolling = false
if buffsP1.get_children().size() > 17 && p1ShouldScroll == false:
	p1ShouldScroll = true
	p1Timer1.connect("timeout", self, "_on_p1Timer1_timeout")
if p1Scrolling:
	var p1ScrollMax = max(0, buffsP1.rect_size.x - buffScrollP1.rect_size.x)
	if buffScrollP1.get_h_scroll() < p1ScrollMax:
		buffScrollP1.set_h_scroll(buffScrollP1.get_h_scroll() + 1)
	elif p1Timer2.time_left == 0:
		p1Timer2.connect("timeout", self, "_on_p1Timer2_timeout")
#Player 2 Scroll Buffs
if buffsP2.get_children().size() <= 17:
	p2ShouldScroll = false
	p2Scrolling = false
if buffsP2.get_children().size() > 17 && p1ShouldScroll == false:
	p2ShouldScroll = true
	p2Timer1.connect("timeout", self, "_on_p2Timer1_timeout")
if p2Scrolling:
	var p2ScrollMax = max(0, buffsP2.rect_size.x - buffScrollP2.rect_size.x)
	if buffScrollP2.get_h_scroll() < p2ScrollMax:
		buffScrollP2.set_h_scroll(buffScrollP2.get_h_scroll() + 1)
	elif p2Timer2.time_left == 0:
		p2Timer2.connect("timeout", self, "_on_p2Timer2_timeout")
func _on_p1Timer1_timeout():
p1Scrolling = true
func _on_p1Timer2_timeout():
p1Scrolling = false
func _on_p2Timer1_timeout():
p2Scrolling = true
func _on_p2Timer2_timeout():
p2Scrolling = false

The scrollBuffs() function is being called in the _process(_delta) function.
EDIT: Forgot to mention I have four timers so far, P1TimerScroll1, P1TimerScroll2, P2TimerScroll1, and P2TimerScroll2. I’m planning to use two timers per player to achieve the stopping and scrolling effect I want.

Have you possibly connected it through the editor?

Gluon | 2023-02-19 07:33

Nvm I found the problem! I forgot to change p1ShouldScroll to p2ShouldScroll. It works now! :slight_smile:
EDIT: I’m still getting the error in my debugger, even though the game works. Any way around this?

CDHouston7270 | 2023-02-19 12:44

:bust_in_silhouette: Reply From: Wakatta

Make the connection conditional

if not p1Timer1.is_connected("timeout", self, "_on_p1Timer1_timeout"):
    p1Timer1.connect("timeout", self, "_on_p1Timer1_timeout")

# rest of code

if not p2Timer2.is_connected("timeout", self, "_on_p2Timer2_timeout"):
    p2Timer2.connect("timeout", self, "_on_p2Timer2_timeout")