Here is an example of the kind of thing I mean:
extends Area2D
@export var AreaName: String = "my default name" # need to use inspector to fill in name
var inputCount: int = 0
func _ready():
pass
func _process(_delta):
pass
func _mouse_enter():
inputCount = inputCount + 1
print(AreaName,": Mouse Entered: ", str(inputCount))
With this one script, as is, you can get an effect like you are looking for. You dont need a separate case for each Area2d. You will just have this one script and attach it to multiple Area2d.
This way you will have a single script with a single case to update if anything needs to change.
If you attach this script to each of your Area2D nodes
-
you will have an “AreaName” field you can type a name into
-
every time the mouse enters the object, you get a message in the console stating which area was entered (by name) and how many times it has entered.
This is the bones of what you need, but you will have to tailor it for the actions and responses you want.
Instead of exporting a name to fill in the inspector, you could export the string holding the message for the dialogue
And instead of detecting the mouse, you can change it to detecting bodies entering or buttons pressed or whatever.
And instead of using calling print statements, you can call you dialogue function.
and, lastly, instead of counting the number of times the mouse enters you could set a bool…something like this:
extends Area2D
@export var FirstMessage: String = "my default message"# need to use inspector to fill in dialogue
var beenEntered: bool = false
func _ready():
pass
func _process(_delta):
pass
func _mouse_enter(): #replace with whatever you want to trigger instead of mouse
if beenEntered == false:
print(FirstMessage) # replace with however you are handling dialogue
beenEntered = true
Now you have one script that you can attach to any area2d, it only gets triggered once for each Area2d, and you can customize the message for each one.
You can also drag resources into the exported field in the inspector. So you can keep your dialogue as a resource.