Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to diagnose runtime errors in daemon objects

Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
08-17-2004 01:29
Runtime errors are pretty infrequent in SL, but they happen, and if they're in a daemon object and happen at 4am in the morning when you're sleeping it's pretty hard to diagnose.

One possible astuce is:

- modify your Debug command to look something like:

CODE

LinkMessage( string message )
{
llMessageLinked( LINK_SET, 0, message, "" );
}

Debug( string message )
{
llWhisper( 0, llGetScriptName() + ": " + message );
LinkMessage( "LASTCOMMAND-=-" + message );
}


Sprinkle Debug statements liberally throughout your program ("function blah >>>", "function blah <<<", etc).

Now, add the following script to your object:
CODE

string sMyScriptName = "PutYourScriptNameHere";

integer bScriptState = TRUE;
string sLastCommand = "";

default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
bScriptState = TRUE;
llSetTimerEvent( 1.0 );
}
timer()
{
integer bNewScriptState = llGetScriptState( sMyScriptName );
if( bNewScriptState != bScriptState )
{
if( !bNewScriptState )
{
llInstantMessage( llGetOwner(), "Scanner " + llGetObjectName() + " script crashed at " + (string)llGetWallclock() + " last command: " + sLastCommand );
}
else
{
llInstantMessage( llGetOwner(), "Scanner " + llGetObjectName() + " script restarted at " + (string)llGetWallclock() );
}
bScriptState = bNewScriptState;
}
}
link_message( integer sendernum, integer num, string message, key id )
{
list arguments = llParseString2List( message, ["-=-"], [] );
if( llList2String( arguments, 0 ) == "LASTCOMMAND" )
{
sLastCommand = llList2String( arguments, 1 );
}
}
}


When the script crashes, you'll receive an IM with the last debug message before the crash.

Azelda
_____________________
Moleculor Satyr
Fireflies!
Join date: 5 Jan 2004
Posts: 2,650
08-17-2004 01:56
Debug? Never heard of it. Is it a real LSL function?
_____________________
</sarcasm>
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
08-17-2004 06:58
Most scripters use a "debug" function as a wrapper around llSay, so they can just comment out the say when releasing, thereby saving us the trouble of going through all the code removing multiple says.
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
08-17-2004 23:12
I notice only one problem with your code Azelda, and that's the usage of llGetScriptState. Unless this bug was fixed behind my back, llGetScriptState returns TRUE even if the script in question has crashed.

llResetOtherScript suffers from a similar, possibly related, bug: it fails to reset scripts that have experianced a run-time error.
==Chris
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
08-17-2004 23:43
Oh, this works perfectly.

You can test it using:

CODE

default
{
touch_start()
{
integer b = 5 / 0;
}
}


Azelda
_____________________