Enter pressed command?

In my game I have the players enter in what their name will be, then hit enter to confirm it. Using the key pressed (text expression) command, how do I write enter in the quotes in order for to register I want enter clicked. Keep in mind, they are typing using a text entry object, so I’m not sure if a key could still be recognized will the text entry object is active.

@Swaggyguy229 Hey. So I tried this out and it’s doable, but you have to be careful with a few things.

  1. You have to use the action to activate / deactivate the input from accepting text, otherwise when you display the typed characters that have been captured in “memory” using the notation MyTextEntryObject.String() it will show all the player key presses from the beginning of the game. Not fun.

  2. You have to use events in the main sheet to isolate the text input from the normal game flow. In my example I use a mouse button click and the “cursor over object” conditions, so when I clicked over the text display object it would enable the text entry object.

  3. Consider this, since once the Text Entry is active, it will capture all the characters regardless of what you do, but that doesn’t mean the inputs won’t work with other conditions, this means you can use a condition that checks if text has been entered and nest the Return keypress condition to avoid always checking for return even in the block of code that activates the general “text input” feature.

  4. If you press Enter / Return, it will store that as the newline character (i.e \n) so you have to delete this from the output string before displaying it. I used the String manipulation expression SubSrt(Actual_Text,Start_Pos,String_Length) I passed the MyTextInput.String() value into the “Text” field on the function expression, then for the length I passed the same value again and after the expression is evaluated (it gives a result in the form of a number) I subtracted -1 So it ends up like this:
    SubStr(MyTextInput.String(), 0, StrLength(MyTextInput.String())-1)

Here’s a screenshot of my events in case you want to inspect that.


To learn more about the string functions please visit the manual:

Manipulate text with expressions [GDevelop wiki] (Explanations)
gdevelop5:all-features:functions [GDevelop wiki] (Actual Expressions)