Getting a variable from a signal

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rustyStriker
:warning: Old Version Published before Godot 3 was released.

I’m using the Area2D and the signal i need gives an Object variable, how can i access it using the connect() function(or another one)

I don’t understand well your question.

Area2D sends you a signal and you can handle it like this, for example:

func _ready():
	area2d.connect("area_enter", self, "_on_object_enters_area")
	# Note: you can also connect the signal from the editor

func _on_object_enters_area(obj):
	# Do stuff with obj

Zylann | 2016-08-31 12:41

Well how do i get the object reference from the signal to the function to do code stuff with it?

rustyStriker | 2016-08-31 13:58

:bust_in_silhouette: Reply From: JTJonny

Guides/Info about signals:
http://docs.godotengine.org/en/latest/tutorials/step_by_step/scripting.html#handling-a-signal
http://docs.godotengine.org/en/latest/reference/gdscript.html#signals

The variable is just sent.

when you see a signal described in the documents like this: area_enter ( Object area ) . The things between the ( ) are automatically sent.

All you have to do is connect your signal with connect() and then give room for the variables in the function that is being called.

example:

func signalTriggerThis(area):
           area.queue_free()

You can also add variables to a signal.
with extra vars: connect("area_enter", self, "_on_object_enters_area", [myVar1, myVar2])
with out: connect("area_enter", self, "_on_object_enters_area")

but you need to make room for them in your function that gets triggered:

func signalTriggerThis(area, myVar1, myVar2):
           area.queue_free()
           myVAr1.queue_free()
           myVAr2.queue_free()