I assumed (not sure why to be honest) that the trigger and dialog were in the same script, in which case what I wrote above may work, but if they are separate, then adjustments will need to be made.
Personally, I would keep them separate if possible, as then the triggers are more flexible.
That said, I'm not sure where the best place to put it would be. If the nodes are separate, then I might change it to something like this (untested):
The (new) trigger script:
extends Area
var _is_player_in_area = false
export (String) var player_node_name = "Player"
signal on_player_interact
# New signal for detecting further interactions
signal on_player_continued_interact
var _has_player_interacted = false
func _ready():
connect("body_entered", self, "_on_body_entered")
connect("body_exited", self, "_on_body_exited")
# Optional:
connect("on_player_interact", self, "_test_interact_function")
connect("on_player_continued_interact", self, "_test_continued_interact_function")
func _process(delta):
if _is_player_in_area == true:
if Input.is_key_pressed(KEY_E):
if _has_player_interacted == false:
emit_signal("on_player_interact")
_has_player_interacted = true
else:
emit_signal("on_player_continued_interact")
func _on_body_entered(other):
if other.name == player_node_name:
_is_player_in_area = true
_has_player_interacted = false
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_interact_function():
print ("Interaction started!")
func _test_continued_interact_function():
print ("Interaction continued!")
Then something like this in the dialog script itself:
Note: I am assuming the on_player_interact signal from the trigger is connected to a function called "on_trigger_interact" and on_player_continued_interact is connected to a function called "on_trigger_continued_interact"
var is_dialog_page_finished = false
func _on_trigger_interact():
StartDialog()
func _on_trigger_continued_interact():
if is_dialog_page_finished == false:
RichTextLabel.set_visible_characters(RichTextLabel.get_total_character_count()+1)
is_dialog_page_finished = true
else:
HandleNode()
I'm not totally sure the code will work though...
As a question: Isn't it a possible to connect the StartDialog() inside of the TRIGGER.gd with the Control node
because we do have the signal that starts the conversation and will be able to sent the signal to the other code to display the text.
It should be possible. You should be able to connect the on_player_interact signal to start the conversation, either in the Godot editor or through code like get_node("Trigger").connect("on_player_interact", self, "function_name_here").