- Edited
target_node is the node that will respond to the signal (first argument) and call its function (third argument).
self
is an arbitrary variable. You could use any other variable that is a node.
target_node is the node that will respond to the signal (first argument) and call its function (third argument).
self
is an arbitrary variable. You could use any other variable that is a node.
no, target_node is the second argument
<source_node>.connect(<signal_name>, <target_node>, <target_function_name>)
@oldSkool said: so with the script attaching to the button, how do i get it to work?
Well first, your calling connect
from yourself, so there's no need for a .
before the function.
Secondly, the second argument should be self, because the method in the third argument is owned by the script, i.e. self
.
connect("button_pressed", self, "_on_button_pressed")
@oldSkool said: no, target_node is the second argument
Yes that's right. I never said otherwise.
this work just fine. what do i need to change to have it to work when i attach the script to the button?
@oldSkool said: this work just fine. what do i need to change to have it to work when i attach the script to the button?
I already gave you the answer.
so basically the second argument will always be self
@SIsilicon28 said: You use
self
if you want to reference the node with the script you are in, and$NodePath
for any other nodes in the scene you want to reference. In this case,Button
is the one with script soself
would be used to reference it. The node path should be relative toself
, so to referencelabel
for instance, you'd have to do$"../label"
.
And as I explained previously, the second argument would be the node that has the method (third argument). If the method were outside this script, the second argument would be the node that has the script, which won't always be self.
But in your case, it will stay self
as long as the method _performAction
is in the same script as the connect function.
still not working. the script to the panel is disable
so $NodePath equal $nodeOfNodeInScene
i mean nodeInScene
if my script is attach to button or panel then i still use self. is this correct?
If the third thing in the argument is in the same script as that connect function then yes the second argument is self
.
@oldSkool said: still not working. the script to the panel is disable
That's because the path to the label is wrong.
i establish that self refer to this so in my case it the panel
can you explain why it not working and how to fix it
scene tree structure Panel label Button
i attach this script to the button but it does not work
extends Button
func ready(): connect('pressed', self, 'performAction')
func _performAction():
$label.text='hey everyone!'
how do i fix the label path
I showed you the path in one of my comments, remember?
$"../label"
Well, label is not a child of button, so you can't access it like that. You can try:
$"../label".text = "hopefully working"
@cybereality might wanna surround the node path with quotation marks there. :P