How to use area detection with multiple instences

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

enter code hereHelp,
I need help for my class. I need to change the area detector to detect different areas but it keeps crashing and the times I do change it and it only works for one instance and for the rest it usually ends whit a crash. (I do have the areas I need to detect in different scenes for adding multiple)

func _on_area_2d_area_entered(area) -> void:#Adds or subractrs if in area
	if area == "Wet":
		humidity = humidity-1
	if humidity < MinHum:
		humidity = MinHum
	Humid_change(humidity,CS_State)
	if area == "dry":
		humidity = humidity+1
	if humidity < MaxHum:
		humidity = MaxHum
	Humid_change(humidity,CS_State)

	
	

README: How to use this Q&A? - Archive - Godot Forum

Which Godot version number are you using? (optional but recommended. Specify an exact version instead of “latest”)

Moreus | 2023-04-04 07:53

I’m using version 4.0

ForgetfulLamb | 2023-04-04 13:12

:bust_in_silhouette: Reply From: pox

You are comparing a node (area) to a string. Find a way to add the wet or dry property to the areas, in a script, and then compare them properly.

something like this in the area script:

@export var type: string

and then compare the strings properly:

if area.type == "wet": do stuff