Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should have a list of your keywords that can be entered. You also save a string that starts out as empty. If the user presses a key you add this letter to the string. You then check all the words in your list for equality to your string. If a word matches, you reset the string to empty and do whatever command you want for the typed word. If the string is part of the beginning of a word you do nothing. If the string is part of none of the words you reset the string to empty.</p> <p>You just have to make sure that a long word never starts with a short word that is also in your list. E.g. if you have for example an "equip" command that let's you equip a new item and an "equipment" command that shows your inventory, this would not work.</p> <pre><code>Module Module1 Private Delegate Sub deleDoSomething() Private Sub HandleMenu() Console.WriteLine("MENU") End Sub Private Sub HandleWalk() Console.WriteLine("WALKING") End Sub Private Sub HandleExit() End End Sub Sub Main() Dim words As New Dictionary(Of String, deleDoSomething) words.Add("menu", AddressOf HandleMenu) words.Add("walk", AddressOf HandleWalk) words.Add("exit", AddressOf HandleExit) Dim currs As String = "" Do While Console.KeyAvailable = False End While Dim bla As ConsoleKeyInfo = Console.ReadKey(True) currs &amp;= bla.KeyChar Dim found As Boolean = False For Each s As String In words.Keys If s = currs Then words(s)() currs = "" ElseIf currs.Length &lt; s.Length Then If Strings.Left(s, currs.Length) = currs Then found = True End If Next If found = False Then currs = "" Loop End Sub End Module </code></pre> <p>I implemented the wordlist as a Dictionary(Of String, Delegate) so I can just call the appropriate Sub by calling <code>words(s)()</code>. The rest is as I wrote above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload