I’ve created a simple text entry within a game which rests on a bar a user clicks so the text entry captures input, but I’m having trouble limiting the inputs a person can make on it.
For example, pressing the RETURN key makes the text appear on a new line.
I’ve tried to catch the return key, by turning off text capturing once it’s pressed, but once I click on the bar to input text again, the next inputs come out in another line. How do I catch this properly?
If you copy the Text Input string into a Text object to display it:
Do = TextInputObject.String() to the text of TextObject
You could check if the Return key was pressed, if so don’t copy the text into the Text object and stop capturing text, otherwise copy the string from the Text Input into the Text object to update it:
[code]Conditions: Return key is pressed
Actions: Deactivate text capture fot TextInput
Conditions: TextInput is capturing the text // will be false if Return was pressed
Actions: Do TextInput.String() to the text of TextObject[/code]
Then, when reactivating the text capturing, you could copy the Text object string into the Text Input, because the Text object has the string without the new lines, check this:
TextInputReturn.gdg (14.8 KB)
I got it working now. Thanks.
Hi, the bug is still there. At first it worked, I don’t know what happened but the problem still persists. :\ I tried to replicate what you did with the example, but I still get the following.
Pressing the Return key causes the text entry to stop capturing, but once I click on the button to input text, this happens.
These are the conditions I used.
EDIT: Also, if you want to try something easy, change the condition “Username_entry capture the text entered with keyboard” in the event 4.1 by the condition “Return key is NOT pressed” (invert the condition), maybe that fixes the problem.
The event that detects the Return key to stop entering text (event 4, “ENTER DETECTION”) has to be placed before the event that copies the entry string in the text object (event 3.2, the last one in “USERNAME”), for example put the group “ENTER DETECTION” above “USERNAME”.
This way the Return key stops the text entry object, and then, in this frame, the string from the text entry object (with the newline) is not copied into the text object.