+1 vote

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.

Godot version 3.2
in Engine by (26 points)

1 Answer

+2 votes
Best answer

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)

by (1,554 points)
edited by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.