If you're allowing the user input raw text, then some effort has to go into sanitizing what they enter once they've hit return, as it may well be anything.
The very least you can do, is strip the spaces/tabs and force the case.
repeat
; request input from the user
INPUT "Thief, Mage or Captain? ->";class$
; strip any spaces or tabs from the head & tail of the class string
test$=trim$(class$)
; force the case to lower, since string compares are case sensitive.
test$=lower$(test$)
; loop until the test$ string equals any one of these
until test$="thief" or test$="mage" or test$="captain"
Print "You are now a ";class$ + "!"
Another common trick in legacy parsers is they only use the first
2 or 3 letters when matching against user input.
eg,
repeat
; request input from the user
INPUT "Thief, Mage or Captain? ->";class$
; strip and spaces or tabs from the head & tail of the class string
test$=trim$(class$)
; force the case to lower since string compares are case sensitive.
test$=lower$(test$)
; grab the first 3 characters from this string
test$=left$(test$,3)
until test$="thi" or test$="mag" or test$="cap"
Print "You are now a ";class$ + "!"
There's still a problem with the word sanitizing & matching though. Since if the player is anything like me and tends to bash out on the keyboard quickly making lot of mistakes, then they're bound to hit characters outside what the program is expecting. Which can make this kind of entry very tedious for end users.
There's a few ways of attacking such problems, I'd probably go for a solution where the user presses a key ( the program polls
inkey$() ) to make a selection, rather than make them manually input the selection, since this by design removes the programmer from most of the sanitizing head aches and is easier for end users also.
But if you have to use input, then an alternative method to find matches could be by
instr. By flipping the comparisons around, we can see if the word we want is in the string they provided. Another way would to be to write a function that strips the illegal characters out of the users input. So only alphabet characters remain.
The slightly more complex solution is to write a parser to break the input text down into individuals words and whatever syntax you need to support also.