hello, so i have this $Button.connect('pressed', self, 'performAction') i understand that this button is listening if someone press it. when it is pressed then performAction but what does self mean?

this is the button. when the user press the button then the method performAction will be call

i don't understand what you mean by this. the button itself is a node that has a function. i didn't do this through a node tab. i did it in a code like this.

func ready(): $Button.connect('pressed', self, 'on_button_pressed')

func _on_button_pressed(): $label.text = 'i got print!'

self refers to the object that is running the acossiated script. So if that connect function were to be called from some button node, then self refers that node. The parameter after that is the method that object owns, which in this case is self.

You are creating the signal from code, sure. But you are still connecting it to a node: .connect(<singal name>, <node to connect it to>, <target function name>)

You were asking what the self in you line $Button.connect('pressed', self, '_on_button_pressed') was. it's the node you are connecting the signal to. And you are using self which references the node your script is attached to.

in my game scene i have panel that have the script and the child is a label and a button . The label will display a text when the button is press so there is no script attach to the button. within my panel script i can access the label.text properties and modify as needed using $ and Button.connect() based on this, so i guess self refer to the Panel node if silicon28 is right, does not make no sense. i thought the button is the self.

But you are still connecting it to a node: .connect(<singal name>, <node to connect it to>, <target function name>) what node am i connecting my signal too? is it Panel?

i trying to call a function when my button get pressed but i don't know what self is? i believe signal is irrelevant. for simplicity

if(buttonIsPress == true){
#call the function _on_button_pressed()
#what is self?
{ 


script 1 the original 
extends Panel        

func _ready():
	 $Button.connect('pressed', self, '_on_button_pressed')
	
func _on_button_pressed():
	#get_node("label").text = "HELLO!"
	$label.text = 'what is up ya!'

this example is based on silicon28 explanation unfortunately it does not work i have a script that is attach to the button. script 2

extends Button

func _ready():
	$Button.connect('pressed', self, '_on_button_pressed')

func _on_button_pressed():
	$label.text = 'what is up everyone!'

sorry i don't know why the call the function go so big

@oldSkool said:

@oldSkool said:

i remove the script from the panel and add the script to the button directly

i think i figure what the self mean. basically when someone press me im gonna connect my self to this function $Button.connect('pressed', self, '_performAction')

also, how come it wont run when you attach the script to the button itself like the above image?

Whatever node you attach a script to is the self from that scripts point of view. If you have the script attached to the panel with the label and button as it's children and you want the signal to be connected to the label then you would write $label-node-name-here instead of self.

@oldSkool said:

The errors don't lie. $Button really doesn't exist. At least not relative to where you are calling it from. You were trying to reference the button that had the script, but what $Button means is a child of self whose name is Button, and self in this case is Button, which doesn't even have children.

now your confusing me. if the script is attaching to the panel then use self and if the script is attaching to a panel then use name!

The script is not attached to panel. Look back at the screenshot.

i know i don't it attach to the panel. i want it to attach to the button

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 so self would be used to reference it. The node path should be relative to self, so to reference label for instance, you'd have to do $"../label".

so with the script attaching to the button, how do i get it to work?