Word.to.string

From AGI Wiki
Jump to: navigation, search

The word.to.string command copies a player-entered word to a string.

Syntax

word.to.string(str sA, wrd wB);

Remarks

This command copies the text of player word wB into string sA. AGI treats words entered by the player as a zero-based array (i.e. w0 is first word, w1 is second word, etc.) However, when using the message special format code, AGI treats '%w1' as the first word.

To minimize confusion when writing logic source code, the WinAGI compiler requires the word argument wB to be one-based, and automatically converts it to zero-based when generating the compiled code. So in the example below, w1 is first word ("look"), and w2 is the second word ("tree").

Possible Errors

If the index of the player word is not valid (for example, if the player only entered two words, and you use 'w3' as the argument value), AGI will read invalid data, resulting in meaningless output.

AGI does not check that a valid string argument is passed. If an invalid string number is used (the limit is 24 [s0 - s23], except for versions 2.089, 2.272 and 3.002.149, which have a limit of 12 [s0 - s11]) AGI will overwrite areas of memory used for other purposes, which may result in crashing AGI.

Example

Code:
[ assume player enters "look tree", and both are valid AGI words
word.to.string(s1, w1);  [ s1 now equals "look"
word.to.string(s2, w2);  [ s2 now equals "tree"

Technical Information

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

See Also

String Commands
Player Entered Words Data Type
String Data Type