- Edited
Hey there all! Unity dev learning the ropes of Godot and I'm trying to make a typing game (Mostly following the tutorial here but substituting out GDscript for the language I'm more familiar with. So far, so good but I've come across an unusual problem when it comes to the Text property of the RichTextLabel. I've been lead to believe that this field is devoid of any BBCode but when I print it, it includes it. Naturally for a typing game this is a big deal! The following is my "enemy" class as it stands
using Godot;
using System;
public partial class Enemy : Sprite2D
{
RichTextLabel prompt;
public String prompt_text;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
prompt = this.GetNode<RichTextLabel>("RichTextLabel");
prompt_text = prompt.CleanString(prompt.Text);
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
GD.Print(prompt_text);
}
and my attempt at doing this is referencing a GD script and calling the function "CleanString"
class_name RegExCustomFunc extends RichTextLabel
func _ready():
pass # Replace with function body.
func _process(delta):
pass
func CleanString()-> String:
var regex = RegEx.new()
regex.compile("\\[.*?\\]")
var text_without_tags = regex.sub(text, "", true)
return text_without_tags
Which naturally, doesn't work and returns "CS1061: 'RichTextLabel' does not contain a definition for 'CleanString' and no accessible extension method 'CleanString' accepting a first argument of type 'RichTextLabel' could be found (are you missing a using directive or an assembly reference?)"
Can't quite seem to figure out where I'm going wrong or if there's a better way to do what I'm doing! Anyone see my issue?
Thanks for reading and have a lovely day!