+1 vote

how can you change the text of a label to something you type in a text Box while you are playing ?

in Engine by (55 points)

1 Answer

+1 vote

One way is to use signals.

Here is an example:

  • Create a new scene, with the following node hierarchy:

Root node (Control, Node etc)
|_ TextEdit
|_ Label

  • Attach a blank script to any of the three nodes
  • Select the TextEdit node, go to the "Node" tab near the "Inspector", and double click the "text_changed" signal
  • Select the node which the script was attached in the "Connect to Node" tree
  • Click on "Connect"
  • Implement the binding function, something along these lines (the exact approach may change depending on the node you attached the script, in my case it was the root node):
    func _on_TextEdit_text_changed():
        var lab = get_node("Label")
        var edit = get_node("TextEdit")

This will keep the label content synchronized with the typed text.

by (50 points)

it does not work .the label does not update.

sorry it works

do you also now how to get the text of a TextEdit to in to a label in a other scene?
But thank you. it help out.

I don't know if you are still in need of help there, but you'd probably benefit from Singletons (autoload). This technique allows you to store and retrieve data between scenes. See this tutorial for details: http://docs.godotengine.org/en/stable/tutorials/step_by_step/singletons_autoload.html

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.