This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+2 votes

I'm trying to create a game similar to a MUD in which the player types a command and then their action appears in a log with the result of that action. I have the commands working but not the log.

I figured I could use string insert() to add each action as a new line of a read only TextEdit node. After playing around with it I can't seem to get insert() or replace() to do anything. I get no errors but it still outputs the original string.

I suppose in my case I could use an array to store the strings and a for loop to concatenate all of them but I wanted to submit this anyways in case I'm doing something wrong or if it's a bug. I'm using the latest stable version of Godot (via steam).

func _ready():
    var text = " sea if this works."
    text.insert(0, "Let's")
    text.replace("sea", "see")

Output: sea if this works.
in Engine by (17 points)

1 Answer

+5 votes
Best answer

My guess is that the insert and replace functions return the altered string but don't alter the original string.

Probably you could do
text = text.insert(0, "Let's").replace("sea", "see")

by (3,370 points)
selected by
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.