Difference between revisions of "WordFail, syntaxFail and pragmaFail"

From SCI Wiki
Jump to navigationJump to search
Line 55: Line 55:
 
<blockquote>
 
<blockquote>
 
<div class="CodeBlockHeader">Code:</div>
 
<div class="CodeBlockHeader">Code:</div>
<syntaxhighlight lang="sci" class="cs">(method (wordFail theString)
+
<syntaxhighlight lang="sci" class="cs">
 +
 +
(method (wordFail theString)
 +
(switch (Random 0 4)
 +
(0
 +
(FormatPrint {Oh, yeah? Well, "%s" this!} theString)
 +
)
 +
(1
 +
(FormatPrint
 +
{You may know the word "%s" but it's beyond 's vocabulary!}
 +
theString
 +
)
 +
)
 +
(2
 +
(FormatPrint
 +
{Oh, yeah? Well, I've got your "%s" right here!}
 +
theString
 +
)
 +
)
 +
(3
 +
(FormatPrint
 +
{You don't need to type the word "%s" to complete this game!}
 +
theString
 +
)
 +
)
 +
(else
 +
(FormatPrint
 +
{Don't you ever say the word "%s" again!}
 +
theString
 +
)
 +
)
 +
)
 +
)
 +
 
 +
 
 +
 
 +
(method (wordFail theString)
 
   (method (wordFail theString)
 
   (method (wordFail theString)
 
   (switch (Random 0 4)
 
   (switch (Random 0 4)

Revision as of 15:01, 31 May 2023

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.

Main Script First, open up your game's "main.sc" script.

New Game Dialog 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)
    )
  )
)

SCI code for wordFail compatible with SCI Companion.

Code:
	
	(method (wordFail theString)
		(switch (Random 0 4)
			(0
				(FormatPrint {Oh, yeah? Well, "%s" this!} theString)
			)
			(1
				(FormatPrint
					{You may know the word "%s" but it's beyond 's vocabulary!}
					theString
				)
			)
			(2
				(FormatPrint
					{Oh, yeah? Well, I've got your "%s" right here!}
					theString
				)
			)
			(3
				(FormatPrint
					{You don't need to type the word "%s" to complete this game!}
					theString
				)
			)
			(else 
				(FormatPrint
					{Don't you ever say the word "%s" again!}
					theString
				)
			)
		)
	)



(method (wordFail theString)
  (method (wordFail theString)
  		(switch (Random 0 4)
    		(0
      		(FormatPrint {Oh, yeah? Well, %s this!} theString)
   			 )
    		(1
      		(FormatPrint {You may know the word %s but it's beyond the game's vocabulary!} theString)
    		)
    		(2
      		(FormatPrint {Oh, yeah? Well, I've got your %s right here!} theString)
    		)
    		(3
      		(FormatPrint {You don't need to type the word %s to complete this game!} theString)
    		)
    		(else
      		(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!")
    )
  )
)

  SCI code for syntaxFail compatible with SCI Companion.

Code:
	(method (syntaxFail theString)
  		(switch (Random 0 2)
    		(0
     		(Print {That doesn't appear to be a proper sentence.})
    		)
    		(1
      		(Print {What in the hell are you talking about?})
    		)
    		(else
     		(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!")
    )
  )
)

SCI code for pragmaFail compatible with SCI Companion.

Code:
(method (pragmaFail theString)
  (method (pragmaFail theString)
  		(switch (Random 0 2)
    		(0
      		(Print {The hell you say?})
    		)
    		(1
      		(Print {You're too smart for this game!})
    		)
    		(else
      		(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!

 

< Previous: Chapter 1 - Global Said() Statements Next: Chapter 3 - Making Actors Move Along Paths >