How do I add arguments to the Control's default gui_input signal via gdscript signal connection (upon node creation)?

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

I have a control node that needs to be instanced into the scene. I connect it via code:

var selected_node
onready var example_node=preload("res://example_node.tscn")
func _ready():
func refresh_nodes():
    var new_node=example_node.instance()
func _on_new_node_gui_input(event: InputEvent, new_argument):
    if event.is_action_pressed("ui_select"):
        print("Node clicked")

I have other errors preventing me from making changes to this code (as I know that it does not cause the crash I’m currently procrastinating a fix on), my question is what I can do to the line with a question mark commented at the end to add the new_node node as an argument to the signal at the connection. I have prepared code using the argument in the handling function. My assumption is that I can list any arguments to add to the connection to the array at the end of the sample code’s line 8 in the signal connection. Will this argument override the inputevent? Will it come before the event? I’ve scoured the API to no avail.

:bust_in_silhouette: Reply From: AlexTheRegent

Yes, you have to add to the array at the end of the sample code’s line 8 in the signal connection. Since you can provide arbitrary amount of arguments to callback and signal itself has fixed amount of arguments, in callback signal arguments will be always first and then provided arguments.
will have next callback:
function _on_new_node_gui_input(event, parent_node)
new_node.connect("gui_input",self,"_on_new_node_gui_input",[$parent, self, new_node])
will have next callback:
function _on_new_node_gui_input(event, parent_node, caller, new_node)

Perfect, I was hoping that’s how it’d work. Now to fix my crash so I can see it happen XD

PercentageProud | 2021-02-04 14:34

How would you do this for a connection made in the editor (not in code). It seems to have only limited argument types and no way to set the “signal emitter” as an argument.

Karl Marx | 2023-04-06 05:07