0 votes

I tried

var text = $LineEdit.text

and

var text = $LineEdit.get_text()
Godot version 3.4.2
in Engine by (28 points)

1 Answer

0 votes

Your first snippet should work fine:

var text = $LineEdit.text

Or, at least, that'll store the text contents of a child LineEdit control in a local variable named text.

I assume the problem might be in the use it in another scene part of your question. With the above code, the text variable (along with its value) will disappear when the scene is changed. If that's the problem, the simplest solution is to create a separate, singleton script that you can store this value (and any other global values in). Such variables will retain their values regardless of scene changes.

So, create a new script (say, Globals.gd), and add your variable to it:

var line_edit_text

Make the script an autoloaded singleton via Project | Project Settings | Autoload. Just select your new Globals.gd script and add it to the list.

Next, store your LineEdit value in the global script like:

Globals.line_edit_text = $LineEdit.text

Then, in any other scene (as needed), retrieve the value from the same global variable...

by (13,082 points)
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 webmaster@godotengine.org with your username.