Create a Text Parser/Text Input Field Scanned for Certain Words

Hey Gdevs!

I’ve been trying to learn Gdevelop by working on a type of game I used to play/create on old Macintosh systems as a kid: A point & click adventure game and text parser (via the software World Builder). I like having a text parser because I feel solving puzzles is more rewarding when the player can issue specific commands based on the scene’s puzzle (rather than just clicking the ‘use’ button and trying every object in the inventory on every object in the scene).

I seem to be getting pretty close to a working text parser with Gdevelop by using a Text Entry object paired with a Bitmap Text object. However, I’m noticing there are a few approaches to text fields, and—being so new at this—I wanted to see if there’s a better way to accomplish my goals.

Here’s a summary of my current set up (as an example, let’s say the player enters “Use screwdriver” into the Text Entry field): If the return key is pressed, the Text Entry object is disabled. Then, I Compare two Numbers set as: StrFind(Parser.String(),“Use”) ≠ -1. Next, I have a sub event that uses the same process to check for the word “screwdriver”. If yes, and the player has a screwdriver in their inventory, the player will use the screwdriver (if screwdriver is missing, system responds “You don’t have a screwdriver!” If the player entered in something like “Use super powers,” or “use spatula” they’ll receive a reply from another text field that says “That didn’t work”, since the only word the events recognized was “use”.

That system seems to be working pretty well for me, but there are some significant snags. First, I’m using a Bitmap Text object to display the typed commands (to avoid blurry fonts), and it’s clunky: There’s no text cursor, text can’t be highlighted, and the backspace key must be pressed for each character to delete (rather than just holding it down). So in short, it’ll work, but it’s not perfect.

Here’s my second method I’m playing with, and ultimately why I’m posting this now: I just discovered the experimental object, Form Control > Text Input. Oh boy did I get excited when I started playing around with this! There’s a lovely text cursor, text can be highlighted, deleted easily, and it’s even got a spell checker to let my player know that “Scerwdriver” is incorrect!

But oh no! The return key creates a new line within the text area, so my events triggered by Return Key is Pressed do not work while the player is within the Text Input Field. Also: My Compare two Numbers condition is no longer working, because StrFind(TextInputObject.String(),“Word being searched”) returns with an error “can’t find an expression…” It seems I can’t pull string info from the Text Input object. I did find a work around where I still include the invisible Text Entry object and then use StrFind on that, but I can’t use this beautiful experimental object Text Input unless hitting return submits the user input. Is there a way to do this?

I feel like I’m so close, and I’m loving the endless possibilities of different types of gameplay I can incorporate with Gdevelop, but I need to figure out this text parser. A couple years ago, I tried using the game engine Adventure Game Creator, but I felt that the text parser within that software was too restrictive: Instead of the system scanning the text for certain words, I had to create a list of specific words to ignore, and that was very tedious. I want to ignore ALL text except for combinations of the correct words to advance the game. That way if a player types “Go on top of the tree, whistle a tune, then use screwdriver”, the command use screwdriver is still recognized. I did see a TextEntryConsole available as an extension within Gdevelop, but the way it’s set up is also pretty strict in regards to what a player might type (first word is a command condition, and words afterward are assigned as an enumerated argument, which—as I understand it—means that I’d need to account for/predict possible combinations of words a player might type). I want players to type any wacky thought that might enter their head.

Any advice, insight, tips & thoughts are greatly appreciated. For those of you that read my entire post, thank you. I know what I’m looking for is a very antiquated system and that most adventure games are simply point-and-click. But I absolutely adored trying different text inputs as a kid and I want to recreate the experience.

I’m so close!

StrFind(TextInputObject.String(),“Word being searched”) returns with an error

Not sure if still having problems but instead of “.String()” use “.Text()”

As for your return key. There might be a better way and I haven’t tested all of the possibilities but if there’s no NewLine() in the input objects .Text() then put the text in a variable. If there is a NewLine(), replace the text with the text from the variable and then do your disable user input and parse the text. I would also add an action to only check for NewLine() when allowing input. Maybe thru a boolean variable condition.

Edit: I noticed in my image I used StrFindLast(). This will still work but I meant to use the simple StrFind()

Thank you Keith! This looks very promising. I’ll work on implementing this setup and report back. I appreciate the help more than you know!

1 Like

This worked beautifully, and I’ve also learned new functions from your example. Going to use this process to move a player command from the input window into an event log panel. Thank you again!

1 Like

Hi Keith—Do you know if there’s a way to use an action to force focus on the Text Input object? If I disable player input while the text is parsed, the player will have to re-click in the box to add an additional command. I can get around that by removing the ‘disable input’ action, but I’m afraid I may run into issues if someone is able to type in something while the previous command is running. Also, I’d love for a player to be able to click the border of the scene and for the text input to become active, rather than the player being required to click exactly in the text input box.

I didn’t see a “focus” action for the Text Input object but I do see that it’s available as a condition.

Sorry if this should be going in a new thread!

I don’t know a lot about the text input but I recall another person asking the same. I don’t believe there’s a set focus.

Edit: Not sure if you know but there’s an extension called “Text Entry Virtual Keyboard” Just search the extensions for “virtual keyboard” Once installed, you assign the behavior to a text entry object. It adds 2 actions to the text entry object; “open mobile keyboard” and “close mobile keyboard”

I tried it and it worked smoothly to open and close the keyboard.

Part of me wonders if it would be better to create your own on screen keyboard instead of opening and closing the phones keyboard.

You could design keys to blend into the theme of your game. You can fake the input even use a sprite or something as a blinking prompter.

It would be harder but you would have total control over the functions.

Thank you again for the quick reply and helpful tips! A virtual keyboard does sound interesting. Or maybe I’ll go back to the hidden text entry object and try not to worry too much about the missing functionality. Most people interested in playing text parser adventure games are probably used to entering simple commands; the need for a fully-functioning text window is more of a luxury than a necessity.

All said, I’m doing this for fun to learn Gdevelop, so no need to overthink things. Thank you again for your help!

1 Like