StringDictCompare
| calling form | description |
|---|---|
StringDictCompare(array,dictentry) |
Performs a StringCompare-like comparison of a string array given by array and the dictionary entry dictentry, returning 1, -1, or 0 if array is lexically greater than, less than, or equal to dictentry, respectively. |
Actually, if you take a look at StringDictCompare’s code, you’ll see
that it just writes the dictionary entry to a string array and does a
StringCompare. Still, a step saved is a step
saved, right?
Here is a silly usage example:
"The puzzlebot turns to you and asks, \"What is in the middle of holes?\""
GetInput("ENTER ANSWER IN QUOTES>")
string(names, parse$, 10)
if StringDictCompare(names, "l") = 0
print "Correct!"
else
print "Wrong!"
Which results in:
The puzzlebot turns to you and asks, “What is in the middle of holes?”
ENTER ANSWER IN QUOTES>“L”
Correct!
Some things to keep in mind:
- The above source code assumes that an array called
nameshas been created. - Just having “l” in
StringDictCompare’s routine calling adds it to the game’s dictionary table (yay self-fulfilling prophecies!). - Also, as implied by the prompt text, the quotation marks around the “L” are important.
- Lastly,
parse$is stored as lowercase text, so you can see that our uppercase “L” in the output did not fool it. Conversely, ifStringDictComparewas looking for an “L” fromparse$, it’d never recognize it, so keep that in mind if you are trying to match a string written fromparse$to a capitalizedobject.nameproperty.
Why The Previous Example Is A Bad Example
If we had asked the player to not put the answer in quotes, we could have just had the line:
if word[1] = "l"
....
Just checking for it automatically adds “l” to the dictionary table so we can use the word array instead of parse$. Still, the author hasn’t replaced this page yet because he couldn’t think of a better example.