Getting Meaning from User Text Inputs This sort of challenge comes up in Text adventure game programs where you want to get the main idea of a player's input. For instance, if "HELLO" shows up, you want your program to respond whether the input is HELLO, THERE! or HELLO. or SAY "HELLO" or just HELLO . The game 'flows' better and the game program looks a lot smarter if it makes an appropriate response to the player's message than if it comes back with ? or I DO NOT UNDERSTAND because the player added a superflurous word or punctuation mark. The usual way to extract meaning from an input is to look for matches to words your program is supposed to recognize. The way you pick out words is, usually, to look for letter groupings not interupted by spaces or punctuation. Here is a sample program which uses a routine for picking out and saving up to seven words ... 10 GOTO 100 29 REM **GET WORDS SUB 30 INPUT "> ";I$: IF I$ = "" THEN 30 32 FOR I = 1 TO 7:E$(I) = "": NEXT I 34 L = LEN (I$) 36 Z = 1:K = 1 38 W = 0: FOR I = Z TO L 40 Q$ = MID$ (I$,I,1) 42 A = ASC (Q$) 44 IF A > 64 AND A < 91 THEN E$(K) = E$(K) + Q$:W = 1: NEXT I 46 K = K + W: IF K > 7 THEN 50 48 Z = I + 1: IF Z < = L THEN 38 50 K = K - 1: RETURN 99 REM *** BEGIN MAIN LINE *** 100 TEXT : HOME 110 DIM E$(7) 120 H = 0 130 GOSUB 30 140 PRINT : FOR I = 1 TO K: PRINT E$(I): IF E$(I) = "HELLO" OR E$(I) = "HI" THEN H = 1 150 NEXT I: PRINT 160 IF H THEN H = 0: PRINT : PRINT "HELLO, JEANNE!": PRINT 170 IF E$(1) < > "STOP" THEN 130 900 END What the subroutine which begins at Line 30 does is to collect groups of letters (actually, capital letters) and put each group in the E$() array. Letters are detected in line 44. At the beginning, you are looking at the first character in the input string I$. If it is a letter it gets added to E$(K)-- which is E$(1) at the start-- and W is set to 1 to indicate that a Word has been found. So long as you keep getting letters, the E$(K) string gets added to. If you run out of characters, the NEXT I ends the loop and you go to Line 46. Otherwise, once any non-letter occurs you fall out of the loop to Line 46. Since W= 1, K is incremented by 1 (to set the E$() index for the next word) and there is a test to exit if you now have 7 words. If you do not have 7 words you will go to Line 48. Z is the starting point for the FOR-NEXT loop in Line 38. It tells you which character in I$ to look at first each time you look for a word. Z starts = 1 as set in Line 36. In Line 48 Z is set to I + 1 because, supposedly, the Ith character was a non-letter which terminated the last word found. You do not need to look at it again; so, you set Z to 'point to' the next character which you have not seen yet. The value of Z is checked to make sure it is not pointing past the end of the string. If it is not, you hop back to Line 38, re-set W (your 'Word Found' indicator) to 0 and start the loop again with a look at the Zth character in I$. The second time you go through the loop and find at least one letter, the Word Found indicator will be set again and the group of one or more letters will be saved in E$(2). Once you run out of characters or you have found 7 words, the subroutine sets K= to the number of words found-- handy to know-- and exits via the RETURN in Line 50. One nice feature of the subroutine is that it does not get fooled by successive non-letter characters into using up E$() slots. So, if the user types in something like MY NAME is PAUL , even with leading and trailing spaces, the routine will exit with E$(1)= "MY" E$(2)= "NAME" E$(3)= "IS" E$(4)= "PAUL" and K= 4 to let you know there are 4 words to deal with. If you wanted to let users enter numbers as well as letters, you would change Line 44 to include the ASCII values for number characters 0-9 ... 44 IF (A > 64 AND A < 91) OR (A > 47 AND A < 58) THEN E$(K) = E$(K) + Q$:W = 1: NEXT I The Main Line of the program includes a couple examples of using the information typed in to make things happen: 1. If you type in HELLO or HI, the program will set H=1 and respond with HELLO JEANNE! (If the program knew the user's name via an earlier entry which saved it as N$, Line 160 could be changed to ... 160 IF H THEN H = 0: PRINT : PRINT "HELLO, "N$"!": PRINT and it could respond HELLO, PAUL! etc. depending upon N$.) 2. If you the first word you type in is STOP, the program will wind up going to Line 900 and executing the END command. As you can see, getting words from inputs is fairly easy. Once you have words, like HELLO or NAME (or GO SOUTH or LOOK or ...) your program can make all sorts of decisions. Rubywand