How can you change the text of a label to you type in a TextEdit ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dezekeerjoran
:warning: Old Version Published before Godot 3 was released.

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

:bust_in_silhouette: Reply From: Samuel Grigolato

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")
        lab.set_text(edit.get_text())

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

it does not work .the label does not update.

dezekeerjoran | 2016-10-16 16:46

sorry it works

dezekeerjoran | 2016-10-16 16:48

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.

dezekeerjoran | 2016-10-16 16:58

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

Samuel Grigolato | 2016-10-22 00:21