Javatpoint Logo
Javatpoint Logo

Line Edit in Godot

In this tutorial we see that how to display text to ourselves as programmers and how to put it in the output how to display it to player. This could be a key component not just in our game but it's also a foundational principle in a lot of games we might be made in the future. We have to go to Godot engine now:

There is a line edit and a text edit. Now the difference them is do we want the player to be able to press return to go a next line or return to enter the text a line edits allows a player to enter a single line of text for example if we want to put in a name or single word a text that it is where we want people to fill out a lot of information so if we're making a role playing game and we want the players to write their own journals we would use a text edit I don't want to do that.

Godot Line Edit

LineEdit Area:

Godot Line Edit

Then we can drag it anywhere we want it. And also make it bigger according to our use.

Godot Line Edit

Output: And here is the box we can write in.

Godot Line Edit

It is a type of text editor like below.

Godot Line Edit

Then we have to add an HBoxContainer. HBoxContainer (Horizontal box container) contains things in a column.

Godot Line Edit

But here we are creating VBoxContainer. We put the LineEdit and DisplayText into the VBoxContainer. So we are dragging LineEdit and displayText like seen below:

Godot Line Edit

We can see below in the screenshot:

Godot Line Edit

Then we can drag the displayText upper then LineEdit like that.

Godot Line Edit

Let's change the alignment of VBoxContainer (Vertical box container) from beginning to end.

Click on VBoxContainer and then change the alignment from begin to end.

Godot Line Edit

Output:

Godot Line Edit

We can change anchors according to our need.We can also change margin and all things from here according to us.

Godot Line Edit

After that we have to select LineEdit and change its font data, size, spacing and all we need.

Godot Line Edit

We can also change or adjust the font size and outline according to our use.

Godot Line Edit

If we run this it give us error which is given below:

Godot Line Edit

It does not works because our script is pointing to something. Drag the DisplayText after the dollor ($) sign in the coding area like below:

Godot Line Edit

Then we have to remove the comma like below screenshot:

Code:

Godot Line Edit

Then the output will come:

Godot Line Edit

If we typing anything in the text box below nothing will happening like below:

Godot Line Edit

Then we are renaming the name LineText to PlayerText.

Godot Line Edit

On its right side of PlayerText after selecting it there is all these options: In the Node option there are many functions which we can use.

Godot Line Edit

Right click on the PlayerText and click on Open Documentation on the link.

Godot Line Edit

Then it will open in our screen:

Godot Line Edit

After scrolling down something:

Godot Line Edit

Then click on text_entered() to connect it from right side.

Godot Line Edit

Here we cannot connecting it so we are closing it.

We are going to select lonny lips here:

Godot Line Edit
Godot Line Edit

There we are connected with the Lonny Lips here in the code section;

Godot Line Edit

Code:

ScreenShot:

Godot Line Edit

Output: Here we can see that this is working now. Anything we write in the TextBox will appear in the screen.

Godot Line Edit

In the below code we add a PlayerText.clear() function for what we write in the text box is seen in the output screen and clear into the Textbox so that we can write another thing in the TextBox. This code is helpful to clear the textbox after written.

Screenshot:

Godot Line Edit
Godot Line Edit

We can also use this code to make it cleaner and understanding easily:

Output:

Godot Line Edit

In our next tutorial we learn about Buttons. How we use TextBox and Buttons simultaneously.


Next TopicGodot Buttons





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA