Inputting into a textbox

I am trying to create log in system for a game and I am having trouble with the input focus. My goal is to have a textbox that will only accept text when clicked on and finish when you press enter. Can anybody help?

Ok, let’s break things up:

  • Here’s an example of text input: Text input
  • Here’s an example of general key detection (for the enter key): 8 ways movement
  • Here’s an example of clicking on a gui node (a box node): Button

Now if you combine these three you have what you need:

  1. Start by detecting when the input field (a box+text node) is clicked. Use the button example above. Set a flag when you detect the click. self.text_selected = true.
  2. When text input is detected AND the self.text_selected flag is set you accept input and show what the user types in the text node.
  3. Finally check when the enter key is pressed. When that happens you clear the text flag, self.text_selected = false.
3 Likes

I am having problems with the script. I used a normal script before by mistake so now I have a GUI script however I cant link it like before so I do not know how to attack the script to make it work.
image

image

You attach a .gui_script to a .gui like this:

Ah Ha! I finally have a working button. Thank you for the help thus far. I am now trying to kind of merge the two together so that when it clicks it then adds to the GUI and not the label however it does not seem to be working. This is what it looks like at the moment.

What happens? PS, please share code as text instead of as a screenshot! You can add code inside three ``` and it will be rendered with syntax highlighting etc

You’re only fetching the text node when the user clicks (at <4>), so the variable text doesn’t exist when the user types or hits backspace.

1 Like