0 votes

I have an event log with occasional choices created with push_meta() method but the tag isn't closed after buttons are displayed causing all the following text to be clickable.
Can it be solved without switching to bbcode_text display?

enter image description here

in Engine by (70 points)

Can you provide your code?

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
    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
    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_meta(respond) # Assign custom value to button
    # !!! >>>>> [meta] tag must be closed here <<<<< !!!

# ==============================
func ReadMeta(meta):    # Pass picked button's value to global variable
    choice = meta

# ==============================
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)
    execute.resume()    # Proceed with scenario
    execute = null
    choice = null

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.