Errors & Debugging
Understand compiler errors and runtime logs.
The validator
knight -check file.sa prints every problem with a line and column. Nothing runs until the file is clean.
text
file.sa:12:5: unknown function "SetPlayerHelth"
file.sa:20:1: expected ';' after event block (required by Knight syntax)
file.sa:30:9: cannot assign string to int variable "score"
Common compiler errors
| Message | Cause and fix |
|---|---|
unknown function | A typo or a native that does not exist. Check the native list. |
expected ';' after ... | Missing ; after a callback, function or config block. |
cannot assign ... | The value type does not match the variable/field type. |
unknown event | The callback name is not in the engine's list. See Callbacks. |
undefined variable | Use the variable before declaring it, or a typo. |
argument N of X expects ... | A built-in function was called with the wrong type. |
Runtime behaviour
- A runtime error in a callback is logged and does not crash the server.
- Boolean callbacks fail open: if they error, the action is allowed.
- Timers and database callbacks run on the tick loop; a slow callback delays everyone, so keep them fast.
Logging from a gamemode
knight
Log("player " + str(playerid) + " joined");
Log("value = " + str(len(parts)) + " / " + typeof(parts));
Inspecting state
knight
player::command("/debug") {
SendClientMessage(playerid, "hp={GetPlayerHealth(playerid)} pos={GetPlayerPos(playerid)}");
Log("money=" + str(GetPlayerMoney(playerid)));
};
Tip
Run
knight -ast file.sa to see exactly how the parser read your file when an expression behaves unexpectedly.