How to create a text box and read from it?

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

Hello, everyone.
I just finished my first program but I want it to be customizable. I mean I want a few variables to be choosable for the user.
For that I just need a few text boxes where the user must be able to write only numbers, and a way to read from those text boxes after pressing the Ok button.

I just need the name of the nodes, this is the first menu I make and I yet don’t know all the names.

Also, is there a way to read from the “Pick color” node too?

Thank you in advance!

I tried this:

extends Label

func Read():
var NbOfEpcs = float(get_node(“LineNbOfEpicicles”).text);
var NbOfSegm = float (get_node(“LineNbOfSegments”).text);
var Rad = int(get_node(“LineRadiusOfCircumference”).text);
var Thicc = int(get_node(“LineThiccness”).text);


func _on_Global_pressed():


It returns an error “Invalid get index “text” (on base: null instance)”
That happens when I press the button which is called Global.

I tried changing this:

	var NbOfEpcs = float(get_node("LineNbOfEpicicles").text);

To this:

	var NbOfEpcs = float(get_node("res://Content/Scenes/Menu/Menu.tscn/LineNbOfEpicicles").text);

Same error.

Edit3: I tried attaching the script to the base node instead of the Label node.
Didn’t work…

:bust_in_silhouette: Reply From: 2D

Yup…you can do both of these OOTB.

For the text, check out the LineEdit node. The ColorPicker is the node for the colors.

You can connect the “text_changed” and “text_entered” signals to wherever you want to check input text. For the ColorPicker node, you can use the “color_changed” signal or just pull out the color.

I created a scene hierarchy as follows for the below code:
-main (all signals connecting to methods in this node)
—error(this is a TextEdit node)

extends Node2D

func _ready():

func _process(delta):

func _on_LineEdit_text_entered(new_text):
	print("Entered Pressed!")

func _on_LineEdit_text_changed(new_text):
	print("Text changed!")

func _on_ColorPicker_color_changed(color):

func _on_Button_button_down():
	var text = int($LineEdit.text)
	if text != 0:
		print("The number ", text, " was entered.")
		#Do somethihng with this number

Here is a link to a good post about saving this data, if needed.

Thank you, it all worked, but the color picker… I need it to be able to set the value of two color variables (color of the circumference and color of the lines). I thought that there was a signal for when people pressed that plus (“+”) button. That way I could set two color variables.
Is there a way to do it?

Edit: Forget it, I made it. Thanks a lot!

C:\Flavius | 2018-05-15 15:00

1 Like