Store data to a variable using keyboard input

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

I found this console online to practice code.

var num1
print("Enter a number: ")

I want to store a value by keyboard.

Here I have a video but it is for python and it does not work for me in godot.

Thanks and regards

:bust_in_silhouette: Reply From: bchmura

The console in Godot is output only… it cannot actually interact with you. So any command line interaction will not work. Python is the closest language to GDScript but it is not actually python (which i think you know)

To take text in from the running game, I think you are looking for the LineEdit control.

I would recommend looking at that and then googling for a video tutorial that fits the style of game you are making. At a glance it looks like you would need to determine how to know when to grab the text (either a button OR a signal reacting to the ENTER key or something).

A video would be much more helpful than my attempt here :slight_smile:

:bust_in_silhouette: Reply From: Gluon

In godot you have something like this

if Input.is_action_pressed("button"):
       Do Something Here

In the project settings, there is an input map. You can set the button to press there and give it a name which you put in the “button” section. So if you go into the project settings, input map and create an input called First_Input and map it to the 2 key then write this code

if Input.is_action_pressed("First_Input"):
       num1 =  2

print("Enter a number: ", num1)

you will be able to change the variable with a button press.

Godot is similar to python but there are quite a few differences too. If you want to learn python I suggest downloading a standard IDE like geany for example. Hope this helps.