How to use the Quick Token extension for parsing input text - MMF1.5
Author: | AlanC
|
Submitted: | 18th July, 2004
|
Views: | 4043
| Rated: |
|
|
I wanted a simple way in which I could separate the verb and noun from a user input edit box. ie "get gun" and then do something with it. Here is how I do it.
In a frams put 3 edit text boxes, these are called "Userinput", editbox 1 and edit box 2. The last 2 should eventually be out of the play area, but put then inside for testing only.
Now add this code.
- Start of frame
(Userinput): Set focus on
(Userinput): Highlight
- (Userinput): has just been modified
(Quick Token Object): Set Base 1
- (Userinput): has just been modified
(Edit object 1): Set text GetToken$("(Quick Token Object)",Edittext$("(Userinput)")," ",1)
(Quick Token Object): Return String when no delimiter
- (Userinput): has just been modified
(Edit object 2): Set text GetToken$("(Quick Token Object)",Edittext$("(Userinput)")," ",2)
(Quick Token Object): Return String when no delimiter
- Edittext$("(Edit Object 1)") = "get"
+ Edittext$("(Edit Object 2)") = "gun"
+ Upon pressing Enter
(Userinput): Set text ""
(Edit Object 1): Set text ""
(Edit Object 2): Set text ""
When you type in "get gun" you will see the Userinput display "get gun", Edit box 1 will display "get" and Edit box 2 will display "gun". When you press enter the edit boxes will be emptied with the (Set text "") lines.
Set the properties of the Userinput edit box to lowercase, then all text will be lowcase in Edit boxes 1 and 2. Makes coding a lot simpler.
I hope it's useful to someone writing an adventure game.
Alan
|
|
AlanC
Registered 27/06/2004
Points 206
|