Home | SCI Documentation | SCI Tutorials | SCI Tools | SCI Wiki | Community

Chapter 16 - Handling The Player's "Said" Input

This chapter will teach you everything you need to know about handling the player's said input. The said input is the text that the user types in, such as "open door" or "look at tree". SCI gives very powerful control over checking what the player typed, and this will guide you through every aspect of doing this.

Getting Started

In the Game Explorer, there's a list of the game's resources.

Script folder Click on the script folder and the list of scripts in your game will appear on the right, along with a preview of the first script.

Rm001 Script Scroll down the list until you read the "rm001" script. Double click on it, and the script editor will open up with the script.

Working With Saids

Checking what the user has entered is done with a combination of if statements and Said() kernel calls. The Said kernel takes a said string as it's parameter, and returns true if it matches what the user has entered, false if not.

Said Script

Scroll down to the handleEvent() method in the RoomScript instance. There, you will find this bit of code.

This is a simple Said call which checks if the player has entered the text "look". If they have, it prints "You are in an empty room".

The Said call checks the words specified in the vocabulary resource (explained in Chapter 7). With this resource, you can have multiple words meaning the same thing. Though our code says "look", because of the vocabulary resource, the player typing "examine" will work as well.

Said String Operators

Said strings can use a number of operators to give you greater control over parsing what the user typed. There are six different operators which can be used: /, ,, <, ( ), [ ], and >.

Operator #1: The Word Separator ( / )

The word separator is the most commonly used of the said string operators. It allows you to check multiple words from the sentence the player types.

Code:
(if(Said("open/door')
  (
theDoor:open())
)

This checks to see if the user entered "open door". If they did, it opens the door using the door class (discussed in Chapter 22).

Example 2:
(if(Said("look/at/tree')
  Print("The tree is bright green!")
)

This checks to see if the user entered "look at tree". If they did, it prints "The tree is bright green!".

There can only be a maximum of three parts to a sentence, so you will never use more than two word separator operators.

Operator #2: OR ( , )

The OR operator allows you to indicate alternative words when checking the player's input.

Code:
(if(Said("open,pull / door')
  (
theDoor:open())
)

This checks to see if the user entered "open door" or "pull door". It accepts either. If they did, it opens the door using the door class (discussed in Chapter 22).

You can put as many OR operators in your saids as you like. Just remember that in many cases, you'd probably be better off adding the words to the same group in the vocabulary resource.

Operator #3: Semantic Reference ( < )

The semantic reference operator. This is similar to the word separator, but can be used in grouping brackets (explained next).

Code:
(if(Said("look<at / tree')
  Print("The tree is bright green!")
)

This checks to see if the user entered "look at tree". If they did, it prints "The tree is bright green!".

The example above works, but is generally not used. Semantic reference operators are generally used with grouping brackets and the no claim operator.

Operator #4: Grouping Brackets ( ( ) )

The grouping brackets allow you to extend the or and semantic reference operators with more complex expressions.

Code:
(if(Said("(turn<on),start / machine')
  Print("O.K.")
)

This checks to see if the user entered "turn on machine" or "start machine". It accepts either. If they did, it prints "O.K.".

Example 2:
(if(Said("(check<out),(look<at) / tree')
  Print("The tree is bright green!")
)

This checks to see if the user entered "look at tree" or "check out tree". It accepts either. If they did, it prints "The tree is bright green!".

You can see here just how useful grouping brackets are, and full use of the semantic reference operator.

Operator #5: Optional Grouping Brackets ( [ ] )

The optional grouping brackets allow you to catch words in the said string which are valid, but not needed.

Code:
(if(Said("climb [< up,on,onto] / tree')
  Print("O.K.")
)

This checks to see if the user entered "climb tree" or "climb up tree" or "climb on tree" or "climb onto tree". It accepts either. If they did, it prints "O.K.".

Operator #6: No Claim ( > )

The no claim operator allows you to check part of a string, then the next part. This is very useful so that you don't need to do if saids for "look this" and "look that". You can simply do an if said for "look>", then if saids for "this" and "that".

Code:
(if(Said("look>')
  (
if(Said("/door'))
    Print("The door is blue!")
  )(
else
    (if(Said("/tree'))
      Print("The tree is bright green!")
    )(
else
      (if(Said("[ /* , !* ]'))
        Print("You are in an empty room.")
      )
    )
  )
)

This checks to see if the user entered "look". If they did, it checks if they entered "look door". If they did, it prints "The door is blue!". Otherwise, it checks if they entered "look tree". If they did, it prints "The tree is bright green!". Otherwise, it checks if they typed "look <anything>" or just "look". If they did, it it prints "You are in an empty room". The last if said is very important. If it is not there, the phrase won't be claimed, and the player will get message stating that the game doesn't understand it.

That concludes Said input. In the next chapter, you will learn about creating and using props!

< Previous: Chapter 15 - Programming The First Room Next: Chapter 17 - Creating and Using Props >
 

by helping to defray some of the costs of hosting this site. If it has been of help to you, please consider contributing to help keep it online.
Thank you.
pixe
Top

© 2013 to present The Sierra Help Pages. All rights reserved. All Sierra games, artwork and music © Sierra.