Removing [meta] tag from RichTextLabel

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Myrmex

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

Can you provide your code?

njamster | 2020-08-01 18:18

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

Myrmex | 2020-08-01 19:34

Did You find the answer ?

Inces | 2023-02-08 18:04

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.

Myrmex | 2023-02-08 21:08

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

    push_meta(Node)
    append_bbcode(text)
    pop()
    append_bbcode(unhyperlinkedtext)

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 :slight_smile:

Inces | 2023-02-09 20:13

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.
RichTextLabel — Godot Engine (stable) documentation in English

Myrmex | 2023-02-10 01:07

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.

Inces | 2023-02-12 13:22