WordFail, syntaxFail and pragmaFail
Chapter 2 - Oh, yeah? Well, "%s" this!
In order to make your game fun and enjoyable, you'll want it to be more intelligent to the player. By default, if the player enters a word not in the vocabulary, or a sentence that doesn't make sense, it will just display a message like "I don't understand "that word"." or "That sentence doesn't make sense.". This can be easily changed.
In Sierra's games, you'll notice that it displays different responses when you enter invalid phrases. If you enter a word not in the game's vocabulary, it will display "Oh, yeah? Well, "the word" this!" or "You don't need to type the word "the word" to complete this game!", or "Don't you ever say the word "the word" again!".
Implementing an intelligent response system is very easy. There are three types of phrase catchers: wordFail, syntaxFail and pragmaFail.
- wordFail, is executed when the player enters a word in the phrase that is not in the game's vocabulary.
- syntaxFail is executed when the player enters an improper sentence.
- pragmaFail is executed when the player enters an valid sentence that is not handled by any said statements.
Adding Response Handlers
The toolbar gives quick access to opening, closing and running games, the resource editors, and the help file. To add the response handlers, you simply need to add the methods by name to your game's instance.
|Scroll down to the game's instance.|
Scroll to the end of it and add the methods to handle the responses. You can add any or all in any order.
You'll naturally want multiple responses, and want them randomly said. To do this, we'll use a combination of a switch statement and Rand() kernel call.
We'll start with the wordFail method. Here's an example:
Code:(method (wordFail theString) (switch(Random(0 4)) (case 0 FormatPrint("Oh, yeah? Well, \"%s\" this!" theString) ) (case 1 FormatPrint("You may know the word \"%s\" but it's beyond 's vocabulary!" theString) ) (case 2 FormatPrint("Oh, yeah? Well, I've got your \"%s\" right here!" theString) ) (case 3 FormatPrint("You don't need to type the word \"%s\" to complete this game!" theString) ) (default FormatPrint("Don't you ever say the word \"%s\" again!" theString) ) ) )
This generates a random number from 0 to 4 (five possible numbers), and displays a response depending on which is generated.
The syntaxFail and pragmaFail operate identical to wordFail, but I'll give examples of them as well:
Code:(method (syntaxFail theString) (switch(Random(0 2)) (case 0 Print("That doesn't appear to be a proper sentence.") ) (case 1 Print("What in the heck are you talking about?") ) (default Print("That's probably something you could do, but this game won't!") ) ) )
Code:(method (pragmaFail theString) (switch(Random(0 2)) (case 0 Print("The heck you say?") ) (case 1 Print("You're too smart for this game!") ) (default Print("Congratulations! You have dumbfounded this game!") ) ) )
The methods all take the string as a parameter. Whether you choose to use it or not is up to you.
You can have as many or as few responses as you like. Just change the random amount and cases.
That sums up global response handlers! Now your game can have attitude!