The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

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

Did You find the answer ?

Yeah, checking this code years later reveals an obvious lack of Text.pop() call after text is added to clear the meta tag. Just tested it, works fine.

How do I use it ?
I thouth it should work like this :


But it still hyperlinks everything. I tried to place pop() in almost every place of this code and it doesn't do it... please help :)

pop() closes the most recent tag so if you call append_bbcode() after the meta it becomes the last one. In theory, you could simply use two pops but, according to the docs, append_bbcode() is working in a different way so you might consider using other methods.

Man, this Label shit is unusable. Even with other methods, adding bbcode manually, it is just impossible to close a tag of metadata containing a real reference to a node. I had to give up.

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 Frequently asked questions and 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 [email protected] with your username.