Log

From AGI Wiki
Revision as of 13:22, 11 April 2019 by Andrew Korson (talk | contribs) (Created page with "The '''log''' command adds an entry to the game's log file. == Syntax == log(msg mLOGMSG);<br /> log("log message"); == Remarks == The '''log''' command is oft...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The log command adds an entry to the game's log file.

Syntax

log(msg mLOGMSG);
log("log message");

Remarks

The log command is often used during debugging of games. It allows the programmer to capture some basic information and save it to a file that can later be examined to make corrections and improvements to a game.

If the game's log file (named 'logfile') does not exist in the game's directory, it will be automatically created. If the file already exists, the log entry is appended to the existing file.

The logfile entry is written in three lines, in the following format:
Room <#>
Input line: <text>
<message>

The room number is the current value if reserved variable v0. The input line value is the most recent line of text that was entered on the input line. The text of message mLOGMSG is added as the last line.

If AGI encounters any file errors while trying to open or write to the logfile, it just ignores the errors, and does not write the log file entry.

Possible Errors

None.

Example

Code:

<syntaxhighlight lang="agi"> [ commonly used entry to track which words players are [ using in a game; can help improve the WORDS.TOK file if (!isset(haveMatch) && isset(haveInput) && unknownWord > 0)

 {
 set(haveMatch);
 reset(haveInput);
 if (unknownWord == 1)
   {
   log("Unknown word: %w1");
   }
 ...
 [ repeat for the other possible word numbers
 ...
 if (unknownWord == 10) 
   {
   log("Unknown word: %w10");
   }
 print("Logged an unknown word.");
 }

</syntaxhighlight>

Technical Information

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

See Also

Debugging Commands
AGI Debugging Information