Custom autocomplete for LineEdit node?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Athakaspen

I want to create a text adventure game where the user will interact with the world by typing commands. I want the command interface to have autocomplete so that the player knows all of their options at any given time. Currently I’m using a LineEdit node, but I’m not sure if it can meet my needs.

For example, if the player types “go to” and presses tab, they’ll be presented with a list of options such as “The Library”, “The Great Hall”, and “Hell”. Is this functionality present in any nodes within Godot? If not, how might it be possible to create this using other nodes? I’m not very familiar with control nodes, so any advice would be greatly appreciated.

:bust_in_silhouette: Reply From: ChristianSF

I don’t think that a LineEdit node alone will do the trick for you. And since Godot isn’t a tool dedicated to creating text adventures, you probably won’t find the one node that does all you have described.

Have you taken into consideration how LucasArts did it back in the days of Maniac Mansion and Zak McKracken? There, players were given several buttons with usable words to click on.

If that’s not your style and you want to go full retro, you’d have to parse the line input as soon as the player has entered any character, check for known words inside the input and derive the player’s intentions from it to finally be able to handle inputs like “use the shovel to plant the pot plant into the plant pot”:wink: Which can be done, as we all know, but it involves some hard work.

So, assuming you got the word recognition done, you could spawn buttons with labels inside them at the input cursor position. Clicking each button will result in appending their label text to the input line.

You’d have to find some way of limiting the possible auto-complete options, otherwise your list of buttons could get quite long (and gui-breaking)… There are, of course, control nodes that offer scroll functionality.