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.
Then we can drag it anywhere we want it. And also make it bigger according to our use.
Output: And here is the box we can write in.
It is a type of text editor like below.
Then we have to add an HBoxContainer. HBoxContainer (Horizontal box container) contains things in a column.
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:
We can see below in the screenshot:
Then we can drag the displayText upper then LineEdit like that.
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.
We can change anchors according to our need.We can also change margin and all things from here according to us.
After that we have to select LineEdit and change its font data, size, spacing and all we need.
We can also change or adjust the font size and outline according to our use.
If we run this it give us error which is given below:
It does not works because our script is pointing to something. Drag the DisplayText after the dollor ($) sign in the coding area like below:
Then we have to remove the comma like below screenshot:
Then the output will come:
If we typing anything in the text box below nothing will happening like below:
Then we are renaming the name LineText to PlayerText.
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.
Right click on the PlayerText and click on Open Documentation on the link.
Then it will open in our screen:
After scrolling down something:
Then click on text_entered() to connect it from right side.
Here we cannot connecting it so we are closing it.
We are going to select lonny lips here:
There we are connected with the Lonny Lips here in the code section;
Output: Here we can see that this is working now. Anything we write in the TextBox will appear in the screen.
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.
We can also use this code to make it cleaner and understanding easily:
In our next tutorial we learn about Buttons. How we use TextBox and Buttons simultaneously.