AGIWiki/said

From ScummVM :: Wiki
< AGIWiki
Revision as of 17:14, 25 October 2018 by Criezy (talk | contribs) (Text replacement - "</source>" to "</syntaxhighlight>")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
AGIWiki


Test commands

The said command is used to evaluate the input entered by the player. It returns TRUE if the player entered text that matches the pattern specified by the argument values.

Syntax

said(WORDGRPNUM1, WORDGRPNUM2, ...)
said("word1", "word2", ...)

Description

The said test command is different to all other commands in the language in that it accepts a special type of parameter and can have any number of parameters. It is used to test if the player has entered certain words.

First, the process of parsing player input needs to be explained. When the player enters a command, the interpreter does the following things with it:

  • Removes certain punctuation characters
  • Assigns each word entered a number starting from 1. When doing this, it tries to find the longest sequence of characters that match a word in the WORDS.TOK file (so for example if the words "door", "knob" and "door knob" were in the WORDS.TOK file and the player entered "turn door knob" then the words would be "turn" and "door knob" instead of "turn", "door" and "knob'). Words in group 0 (usually things like "a", "my", "the') are skipped (not assigned numbers).
  • If one or more words that are not in the WORDS.TOK file are found, it will set v9 (unknown_word_no in the template game) to the first unknown word.

Note: The above is based purely on observation. I am not sure if the interpreter does exactly this, or in this order.

Once the player input has been received, flag 2 (input_recieved in the template game) is set and flag 4 input_parsed in the template game) is reset.

When the said test command is used, it goes through each word given as a parameter and compares it with the corresponding word entered by the player. If they are the same (or are in the same word group), then it continues onto the next word. The comparison is not case sensitive. If all the words are the same, and there are no entered words left over, then the said command returns true and sets flag 4.

There are a couple of special word groups:

Word group 1: "anyword" - if this word is given as a parameter, then any word will do. So if you test for said ("eat", "anyword" ) then the result will be true if the player enters "eat cake", "eat chocolate", "eat worm", eat sword", etc.

Word group 9999: "rol" (rest of line) - this means the rest of the line. If you test for said rk ill", "roi") then he result will be true if the player enters "kill lion", "kill lion with sword", etc.

Remarks

  • Test commands are only valid in an if statement.
  • This statement can be combined with the Not operator to create a 'did not say' test.
  • The said command is unique from all other AGI commands in two respects. First the argument values are 16 bit numbers, not 8 bit. Second, the number of arguments is variable (but must be at least one).
  • The argument values are 16 bit numbers because they are compared against the word group numbers that are stored in the WORDS.TOK file.
  • The compiler will accept numbers as the word group arguments, or literal text values that correspond to words in the WORDS.TOK file. The compiler will insert the corresponding word group number into the compiled code automatically.
  • The interpreter parses any text that the player enters as input. The said command compares its arguments against the parsed input.
  • A detailed explanation of how the comparison is carried out by the interpreter can be found in the said command section of the Player Input topic.
  • The actual arguments stored in compiled code include the number of arguments in the command as an 8 bit number, followed by the 16 bit word group numbers. The compiler does not require the programmer to enter the number of words; it automatically calculates the total number of words, and inserts it into the compiled code during compilation.

Example

 if (said(2124)) {  //assume word number 2124 = "look")
   print("You look around.");
 }

 if (said("look")) {  //same as above, but using literal text instead of number
   print("you look around");
 }

 //use "rol" (9999) and "anyword" (1) for special cases
 if (said(2124, 1)) {  //same as: said("look", "anyword")
   print("It looks ok.");
 }

 if (said(2124, 9999)) {  //same as: said("look", "rol")
   print("Ignore that.");
 }

Technical Information

Required interpreter version Available in all AGI versions
Bytecode value 14 (0x0E hex)

Sources