Okay, I tested the code and made a few changes, since I had some syntax errors. Here is the code from the test/prototype project:
extends Area
var _is_player_in_area = false
# We will use the node name to detect if the node is the
# player or not. You may need to change this depending
# on how your game is setup and/or project requirements
export (String) var player_node_name = "Player"
# Custom signal (I’m not sure if the syntax here is correct...)
signal on_player_interact
# track if the player has interacted so we do not restart
# the interaction while the dialog is going
var _has_player_interacted = false
func _ready():
connect("body_entered", self, "_on_body_entered")
connect("body_exited", self, "_on_body_exited")
connect("on_player_interact", self, "_test_function");
func _process(delta):
if _is_player_in_area == true and _has_player_interacted == false:
# In this example, the interact key is E, though you
# probably want to change this with an action
if Input.is_key_pressed(KEY_E):
emit_signal("on_player_interact")
_has_player_interacted = true
# Interact prompt UI should, probably, be disabled here.
func _on_body_entered(other):
if other.name == player_node_name:
_is_player_in_area = true
_has_player_interacted = false
# If you have UI to show (like “press E to interact”)
# then you could enable it here.
func _on_body_exited(other):
if _is_player_in_area == true:
if other.name == player_node_name:
_is_player_in_area = false
_has_player_interacted = false
func _test_function():
print ("Interacted!");
The issue I was having was that the Godot didn't like "
and I used the wrong name for the Input function. I was not able to reproduce the signal issue, it just worked, though to be fair I just connected the signal to simple function within the same script.
(Sorry about the delay! I thought I could get to it yesterday, but it didn't work out)