User Tools

Site Tools


scripting:reference:debugging

Debugging Scripts

When your script isnt working as you'd expect, there's a few ways of going about finding out why..

Script Trace

Use the command *scripttrace [mode] to activate the script trace functionality. When this is on, as the server runs through each line of script code it will print out what its doing. Sometimes this is useful just to confirm which lines of script are running (e.g. to confirm that you are actually triggering the event you thought you were triggering). Sometimes the script trace will also show when a line fails to execute because its not formatted correctly (or etc). Note that the script trace is automatically turned off when you leave the world.

The mode for script-trace determines where the trace output is sent

Mode 0 = Trace off
Mode 1 = Print to world-server 'Script' tab
Mode 2 = Print to world-server 'Script' tab and send to the client's LogScriptTrace stream
Mode 3 = Just send to client LogScriptTrace stream
Mode 4 = Just send directly to the client's chat window

If you don't have access to the server executable (e.g. if it is being hosted for you on another machine), sending the output to the client will allow you to trace the execution remotely. To view the output on the client's LogScriptTrace stream you will need to set up a debug config.

Script Trace Example

Example bugged script:

Event( "&command", "bugtest" )
{
   sysAddBuildngWorld( 1, %PLAYER%, $gPlayerWorldX, $gPlayerWorldY )
}

Oh no.. using &bugtest isnt adding a building.. whats wrong? Script trace shows:

(0000) [EVENT] (Mit}: &command <bugtest>
(0001) ERROR: Script function sysAddBuildngWorld not found

which at least gives you a clue and hopefully you'll work out the spelling bug from that :]

Adding prints

If the trace hasn't helped resolve your script issue, often the next step is to add some message output.

E.g. If you've got a script like:

if ( $inputVal == 1 )
{
    *playereffect %PLAYER% 1
}

and your player effect is not triggering, you might want to temporarily change the script by adding a print line to show you the input value, e.g.

*say Input val is $inputVal
if ( $inputVal == 1 )
{
    *playereffect %PLAYER% 1
}

Using *say is fine if you're just testing alone but that does send the output to everyone connected.. *msg %PLAYER% (or even just *msg and then your gamename) limits the output to just the player running the script or you.

Ask around

There are lots of quirks and limitations of the game's custom scripting language, some of which are obscure and largely indefensible :]. Sometimes you'll have to fall back to the last resort and ask someone to help. If you're signed up for the game's patreon you'll have channels there with other folk who might be able to help. Otherwise try posting about your issue on the game's discussion channels on steam.

scripting/reference/debugging.txt · Last modified: 2023/04/24 04:06 by mit

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki