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.
0 votes


I am trying to get the text from a line edit node, and i tried this:

 onready    var sendSound : LineEdit = $"/root/Server/HBoxContainer/VBoxContainer/HBoxContainer/VBoxContainer/InputSound"

doesnt seem to work, i tried also:

onready var sendSound : LineEdit = $HBoxContainer/VBoxContainer/HBoxContainer/VBoxContainer/InputSound

which this gave me through its auto-populate or auto-correct, but that doesnt work... WHAT AM I DOING WRONG??!!

in Engine by (64 points)

1 Answer

0 votes


If you want the text when someone types and presses enter, add a signal on the LineEdit node to do this.
or are you trying to do something else?

by (2,065 points)

HEy deaton64, yes when someone enters text in the LineEdit, then presses a button, I want to capture that text into a variable, is there an easy way? you said add a signal?

Usually, you enter text, press enter and that's when the text is read.
Click on your LineEdit node in the Scene. Then in the Inspector click on the Node tab.
Double click on either textchanged or the textentered signal and connect those to your code.
Then you end up with something like this to get the text:

func _on_LineEdit_text_entered(new_text: String) -> void:

Or, if you want to grab the contents of the text box when someone hits a button, you can: print($LineEdit.text)

cool thanks, for some reason, i am not sure why, i tried yours, and still didn't work.... then I found this when i right-click the child node: Copy Node Path

and added the .text like yours, and it worked... weird weird thing is... i did this before, were i copied the path like that, and tried it... and still didn't work, not sure what is the difference between yesterday and today.... but its working... big thank you :)

so it worked as such, I right click, copy node path, then added .text


Glad it works.
Be careful if you move the line edit object in the scene tree, the node path will change, but you code will point to the object in it's original place.

You can get round this by searching for the node and assigning it to a variable and using that to reference the object. A bit like you were trying in the original post.

onready var sendSound :LineEdit = find_node("InputSound")

then you can access the text like this: print(sendSound.text)
Makes your code neater as well.

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.