Can an Area's body enter signal pass a variable to its recipient node?

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

Hi All.
I have a bunch of area nodes placed at different distances from the player - I want to use them to measure the length of a throw of a rigid body by the player. Basically, the length would be measured by area nodes emitting signals to a ‘measurement’ function once the rigid body hits the ground in their area (ie, enters them).

I want to only build one function to collect the lengths and display them, therefore I am thinking of passing a length value from each area node into the display function’s length variable. Something like this:

Area node’s code:

extends Area

onready var thrownObject = get_node(“root/thrownObject")

func _ready():
	connect("body_entered", thrownObject, “measure_length.length_variable = 1000”) 

Display function’s code:

func measure_length():

 var length_variable
	if body.name == “thrownObject”
		print(“Object landed on 1000”)

Or something along these lines. What would be the best method to achieve this?

:bust_in_silhouette: Reply From: Asthmar

Send a signal to the script that holds the length var . The body enters the area, then the area sends a signal to the script with the var and tells that script to change the var to the new length and print it.

Or you can use a singleton which can hold a global var. A little bit more advance but cleaner than the other option Singletons (Autoload) — Godot Engine (stable) documentation in English