I think I figured it out. I believe @cybereality was right. I used a second variable to hold event state and when I did, it solved the issue. I also rearranged nodes and such and I must have had a hiccup there. Honestly, I rebuilt it ground up and now it works great. I also cleaned up the state machine to make the code a bit more readable. I am loving state machines, in case it is not obvious. =)
A note to humbly remember variables are references, so you always gotta check them.
My solution:
extends Area2D
class_name eventPrototype
# class tree is area 2d parent
# children are CollisionShape2D, ColorRect, AnimationPlayer w AnimatedSprite child
enum eventStatus {BEFORE, DURING, AFTER}
var currentEvents = eventStatus.BEFORE
var nextCurrentEvent = eventStatus.DURING
var can_run_event = false
# animation player w animated sprite child
onready var _prompt = $PromptPlayer
onready var _promptBox = $PromptPlayer/Prompt
### on ready, hide sprite and connect enter/exit signals __________________
func _ready():
_promptBox.hide()
self.connect("body_entered", self, "on_body_entered")
self.connect("body_exited", self, "on_body_exited")
pause_mode = self.PAUSE_MODE_PROCESS
### check if player is present to validate event can play _________________
func on_body_entered(body):
if body.name == "Lydia":
can_run_event = true
print("Event box enter.")
prompt_on()
func on_body_exited(body):
if body.name == "Lydia":
can_run_event = false
print("Event box exit.")
prompt_off()
### handle input to access event and check state machine __________________
func _input(event):
if Input.is_action_just_pressed("ui_accept"):
print("Can run = " + str(can_run_event))
if can_run_event == true:
currentEventstatus()
### core event state machine ______________________________________________
func currentEventstatus():
match currentEvents:
eventStatus.BEFORE:
before_state()
eventStatus.DURING:
during_state()
eventStatus.AFTER:
after_state()
### reveal visual prompt and vice versa ___________________
func prompt_on():
_prompt.play("visible")
_promptBox.show()
func prompt_off():
_promptBox.hide()
### actions for states _____________________________________
func before_state():
print("Event ready...")
### allows for "double clicking" event to prevent accidental trigger
event_next()
func during_state():
nextCurrentEvent = eventStatus.AFTER
get_tree().paused = true
print("An event triggered.")
### put an event here
event_next()
func after_state():
currentEvents = nextCurrentEvent
get_tree().paused = false
print("Event already done.")
can_run_event = false
func event_next():
currentEvents = nextCurrentEvent