Project is just a Control node with RichTextLabel child.
# ==============================
extends Control
# ==============================
onready var Text = $RichTextLabel
var execute # Calls method and stores its state
var choice # Stores value when player makes decision
# ==============================
func _ready():
Text.connect("meta_clicked", self, "ReadMeta") # If [meta] text is clicked
AddLine("Testing123")
execute = Scenario_A() # Print text sequence with options
# ===============================
func Scenario_A():
AddLine("All systems OK")
AddLine("Click a button:")
AddForm("A", "[ Option A ]", Color(.6,1,.6)) # Draw button with value "A"
AddForm("B", "[ Option B ]", Color(1,.6,.6)) # Draw button with value "B"
AddLine() # Newline
yield() # Freeze sequence until any button is pressed
# Method is resumed here with picked choice stored in global variable
AddLine(str("Option ", choice, " picked"))
yield(get_tree().create_timer(.3), "timeout")
AddLine("Regular text")
yield(get_tree().create_timer(.3), "timeout")
AddLine("Regular text")
# ==============================
# Print plain text and newline
func AddLine(text="", color=Color.white, style=0):
if !color: color = Color.white # Allows calling method with null arg
Text.push_color(color)
if style in [1, 3]: Text.push_italics()
if style in [2, 3]: Text.push_bold()
Text.add_text(str(text, "\n"))
# ==============================
# Print interactive text
func AddForm(respond=null, text="", color=Color.white, _style=0):
if !color: color = Color.white # Allows calling method with null arg
Text.push_color(color)
Text.push_meta(respond) # Assign custom value to button
Text.add_text(text)
# !!! >>>>> [meta] tag must be closed here <<<<< !!!
# ==============================
func ReadMeta(meta): # Pass picked button's value to global variable
choice = meta
ResumeMethod()
# ==============================
func ResumeMethod(): # Continue stored method from it's current state
if !execute: # Button pressed but no method to pass it to
AddLine("Unexpected function call", Color.red)
return
execute.resume() # Proceed with scenario
execute = null
choice = null