Said

From AGI Wiki
Jump to navigationJump to search

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", ...)

Remarks

Test commands are only valid in an if statement.

The said command compares its arguments against the parsed input.

The said test 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 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. Compilers do not require the programmer to enter the number of words; they automatically calculate the total number of words, and insert it into the compiled code during compilation.

The argument values are 16 bit numbers because they are compared against the word group numbers that are stored in the WORDS.TOK file. Most compilers 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.

When the said command executes, AGI first checks reserved flag f2 (input received) to determine if the player has entered any input. If not, the said command returns FALSE. It then checks reserved flag f4 (said found match) to determine if a previous said test has already accepted the player's input. If so, the said command returns FALSE.

After verifying that the player has entered input and that the input has not yet been accepted, AGI enters a loop to check the words in the said command against the words entered by the player (and stored in the player-entered word data arrays).

If the word in the said command matches the corresponding player-entered word, AGI moves to the next word. If all words match, and the number of words entered by the player match the number of words match the number of words being tested in the said command, then reserved flag f4 (said found match) is set to TRUE and the command returns a value of TRUE. Otherwise, the command returns a value of FALSE as soon as it finds a word that doesn't match.

There are two special word values that can be used in the said command. If the test word value in the said command equals 1 ("anyword"), then it automatically matches the next word in the player-entered word data array regardless of its actual value. If the test word value in the said command equals 9999 ("rol") then it matches the next word and the rest of the line is ignored. Some examples illustrate how the said command works:

 Player types "look at the brick wall" 
 After parsing, the player-entered words are "look", "brick", "wall"

 said("look") returns FALSE (number of words are different)
 said("look", "down", "floor") returns FALSE(second word doesn't match)
 said("look", "brick", "wall") returns TRUE (all words match)
 said("look", "anyword", "wall") returns TRUE (second word matches regardless of what player entered)
 said("look", "rol") returns TRUE (rest of line matches regardless of what player entered)

As mentioned above, words from wordgroup 0 are ignored by AGI, and normally don't return TRUE in a said command. However, there is a bug in AGI which will cause said(0) to return TRUE when an unknown word is detected. When the unknown word is detected, a zero is stored in the player-entered word data array at the location of the unknown word; the said command will consider this a match for wordgroup 0, and return TRUE.

The said test command can be combined with the NOT operator to test if the player did not type a specific phrase.

Possible Errors

None.

Example

Code:

<syntaxhighlight lang="agi"> if(said(2124))

 {  [ assume word number 2124 = "look")
  print("You look around and see nothing of interest.");
 }

if(said("look"))

 {  [ same as above, but using literal text instead of number
  print("You look around and see nothing of interest.");
 }

[ use "rol" (9999) and "anyword" (1) for special cases if(said("look", "anyword"))

 { [ doesn't matter what word comes after "look"
  print("It looks ok."); 
 }

if(said("look", "rol"))

 { [ any number of words after "look" is OK
  print("Ignore that.");
 }

</syntaxhighlight>

Technical Information

Required Interpreter Version: Available in all AGI versions.
Byte-Code Value: 14 (0x0E hex)

See Also

Test Commands
Player Input Commands