How do I turn what's in a line edit into a variable i can use in other scenes?

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

I tried

var text = $LineEdit.text


var text = $LineEdit.get_text()
:bust_in_silhouette: Reply From: jgodfrey

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,, 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 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…

1 Like