Godot Version
4.3
Question
I have set up dialogues in my game, I have 2 dialogues right now, welcome and tutorial, the flow goes like this: press F => welcome show => press F again => tutorial show.
now when reaching tutorial I don’t want the player to press F, so he won’t skip tutorial until completed, I set up 2 bools, one for welcome_completed
, and the other is the can_trigger_dialogue
for F key. I have tried many attempts to get it working, but haven’t succeeded, if anyone has any suggestions, please share.
dialogue script (located in the level scene)
func _unhandled_input(event: InputEvent) -> void:
# Check if F key is pressed and we are allowed to trigger dialogues
if event.is_action_pressed("dialogue") and Globals.can_trigger_dialogue:
print("Dialogue action triggered!")
# Handle Welcome Dialogue
if not Globals.welcome_completed:
# Show the welcome dialogue
DialogueManager.show_dialogue_balloon(load("res://dialogues/welcome.dialogue"), "start")
Globals.set_welcome_state(true) # Update global flag
Globals.set_can_trigger_dialogue(false)
return
global script (not located in scene at all)
var can_trigger_dialogue: bool = true # for triggering dialogue by pressing F
var welcome_completed: bool = false
var track_tutorial_inputs: bool = false
var dialogue_active: bool = false
var tutorial_completed: bool = false
var discover_shown: bool = false
func set_can_trigger_dialogue(state: bool) -> void: # refer to F key
can_trigger_dialogue = state
print("Dialogue trigger state set to: ", can_trigger_dialogue) # Debug print
# Set welcome state
func set_welcome_state(state: bool) -> void:
welcome_completed = state
print("Welcome state set to: ", welcome_completed)
# Set tutorial state
func set_tutorial_state(state: bool) -> void:
tutorial_completed = state
print("Tutorial state set to: ", tutorial_completed)
# Process input from the player
func process_input(event: InputEvent) -> void:
# Check if tutorial is complete and disable dialogue triggering
if tutorial_completed:
set_can_trigger_dialogue(true)
return
elif welcome_completed:
set_can_trigger_dialogue(false) # Disable dialogue during the tutorial
return
else:
set_can_trigger_dialogue(false)
# Track tutorial inputs if enabled
if track_tutorial_inputs:
if event.is_action_pressed("left"):
required_keys_pressed["left"] = true
elif event.is_action_pressed("right"):
required_keys_pressed["right"] = true
elif event.is_action_pressed("attacking"):
required_keys_pressed["attacking"] = true
# Check if all required inputs have been pressed
if all_keys_pressed():
end_tutorial()
# Ends the tutorial and starts the next dialogue
func end_tutorial() -> void:
DialogueManager.show_dialogue_balloon(load("res://dialogues/teach.dialogue"), "proceed")
ui_prompt.visible = false
track_tutorial_inputs = false
tutorial_completed = true
dialogue_active = true
# Checks if all required keys/actions have been pressed
func all_keys_pressed() -> bool:
for key in required_keys_pressed.keys():
if not required_keys_pressed[key]:
return false
return true # All required keys have been pressed
# Input function to capture player's input
func _input(event: InputEvent) -> void:
process_input(event)