Why would Signal method be called twice ?

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

Hello,

I have a CanvasLayer/Control/Texture Button, where on pressed button I emit_signal. and print returns that the signal was emitted once.

Then in the ready function of the scenes listening I connect the signal.

get_node("GUI/Abilities").connect("emitted_signal", self, "OnConnect")

func OnConnect():
print(connected) 

The problem is that print(connected) prints out twice. Any ides why that would be ? Was looking into pressed/released related issues but I have other texture buttons under the GUI that work just OK with seemingly the same setup. Also I am pretty sure this was working when I set it up so I am mostly looking into what would cause this to happen. Any help appreciated.

I would recommend to use breakpoint and print_stack() to debug this.

whiteshampoo | 2021-04-15 11:40

Thank you .
Frame 0 - res://Scenes/Enemies/Knight.gd:60 in function ‘_ready’
Frame 1 - res://GameRoot.gd:120 in function ‘show_map’
Frame 2 - res://GameRoot.gd:39 in function ‘_ready’

So if I can read this correctly the GameRoot class which handles loading of the maps somehow triggers the function to run for the second time.

AltoWaltz | 2021-04-15 14:07

I need the code to say more

whiteshampoo | 2021-04-15 19:38

GameRoot code:

Frame2:

elif DataImport.load_slot == "Slot2" and (DataImport.save_data2["GameRoot"]["Map"]) == str("Map") and map_check.file_exists("user://savegame2.json") and DataImport.load_saved_game == true:
	show_map("Map")

Frame1:

func show_map(map_name):
	if self.current_map != null:
		get_child(2).queue_free()
	self.current_map = load(maps[map_name]).instance()
	if map == "Map":
		self.current_map.name = "Map"
	self.add_child(self.current_map,true)

Frame 0 code is above.

AltoWaltz | 2021-04-16 05:58

:bust_in_silhouette: Reply From: 1shevelov

I had an issue with PopupMenu sending two id_pressed() signals on a single click.
I wasn’t been able to find the source of the problem, but mitigated it registering the start of handling method with OS.get_ticks_msec(). Ignored the next signal if it is received in less than 100ms (could be 1ms as well).