How to keep a string with a line_edit?

Hello, so i would like to know, how can we do a system where you put your name in a line_edit and it kept it. Like in pokemon where you insert your name and it’ll be on your profile.
I’ve tried with the line_edit but each time i do it, it can’t be store as it doesn’t give me the name that i’ve put


Godot Version

^ this is my script, the name_give is a global variable and it prints “the name isAA” which is what I’ve written in my line_edit (which is “AA”)


image

^ So here the print gives the “name_give:<LineEdit#28353496328>”

Question

How can I store the name(the line_edit) in other scene ? I've already tried const and global variable and i really don't know how to do it. Thank you.

If this is going to be needed in other places, I’d suggest putting it in a global script; see Project->Project Settings->Globals. If you make a global script called (say) PlayerInfo and make it something like:

# PlayerInfo

extends Node

var Nickname: String = "some default name"

Then in your existing code you can have:

func _on_done_pressed():
    PlayerInfo.Nickname = line_edit.text
    [..stuff...]
1 Like

How did you define name_give? it seems to be highlighted like a singleton/autoload.

Assigning a varaible to the line_edit.text will store a copy of the string. Could you explain more about what you are trying to do specifically? What troubles are you specifically having, where do you need to use the line_edit text and where is it being set?

1 Like

THANK YOU, It worked thank you very much THANKS