Difference between revisions of "LSL Errors"

From Second Life Wiki
Jump to navigation Jump to search
(add demoeElseIfSyntaxError and mention that only Windows chokes)
m (reword section headings and Stack-Heap collision for clarity)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header}}


==Script run-time error messages==
==Run-time error messages==


A script may stop running, and chat at you the complaint "Script run-time error", followed by another complaint such as:
A script may stop running, and chat at you the complaint "Script run-time error", followed by another complaint such as:


===Lists may not contain lists===
===Script run-time error: Lists may not contain lists===


Don't try adding a list into a list.
Don't try adding a list into a list.


===Math Error===
===Script run-time error: Math Error===


Float divided by zero, integer divided by zero, etc.
Float divided by zero, integer divided by zero, etc.


===Stack-Heap Collision===
===Script run-time error: Stack-Heap Collision===


The Stack has collided with the Heap.<br/>The LSL memory space contains three sections Bytecode, Stack and Heap which all must be contained in 16KiB of memory.
The Stack has collided with the Bytecode or the Heap.


This can occur if the running script is too big. The script compiles and saves successfully, but when an object containing it is instantiated the script crashes.
Each script runs inside 16 KiB of memory divided out among Bytecode, Stack, and Heap.
 
You can cause collision by compiling too much script, which produces too much Bytecode. The script compiles and saves successfully, but when you rez an object containing the script, the script crashes, immediately or while running.


See [[llGetFreeMemory]].
See [[llGetFreeMemory]].


==Sample scripts that demo script run-time error messages==
===Example Scripts===
 
Compile and run examples like these to experience the script run-time errors.


<pre>
<pre>
Line 47: Line 51:
</pre>
</pre>


==Surprising compile-time ERROR messages==
==Compile-time error messages==


The SL GUI may reject some code that you feel is perfectly clear, printing ERROR at you and then explaining with some further complaint.
The SL GUI may reject some code that you feel is perfectly clear, printing ERROR at you and then explaining with some further complaint.
Line 74: Line 78:
For example, once upon a time, Mac OS X could compile twenty-five cascaded else-if's, and Windows could not:
For example, once upon a time, Mac OS X could compile twenty-five cascaded else-if's, and Windows could not:
<pre>
<pre>
demoeElseIfSyntaxError(integer count)
demoElseIfSyntaxError(integer count)
{
{
     if (count == 0)
     if (count == 0)

Revision as of 07:33, 23 September 2007

Run-time error messages

A script may stop running, and chat at you the complaint "Script run-time error", followed by another complaint such as:

Script run-time error: Lists may not contain lists

Don't try adding a list into a list.

Script run-time error: Math Error

Float divided by zero, integer divided by zero, etc.

Script run-time error: Stack-Heap Collision

The Stack has collided with the Bytecode or the Heap.

Each script runs inside 16 KiB of memory divided out among Bytecode, Stack, and Heap.

You can cause collision by compiling too much script, which produces too much Bytecode. The script compiles and saves successfully, but when you rez an object containing the script, the script crashes, immediately or while running.

See llGetFreeMemory.

Example Scripts

Compile and run examples like these to experience the script run-time errors.

default
{
    state_entry()
    {
        list once = [];
        list twice = [once, once]; // Script run-time error: Lists may not contain lists
    }
}
default
{
    state_entry()
    {
        float one = 1.0;
        float zero = 0.0;
        float quotient = one / zero; // Script run-time error: Math Error
        llOwnerSay((string) quotient);
    }
}

Compile-time error messages

The SL GUI may reject some code that you feel is perfectly clear, printing ERROR at you and then explaining with some further complaint.

ERROR: Type mismatch

You must name the .x .y .z .s components of a vector or rotation that you're assigning, you can't assign them all at once from a list, for instance:

default
{
    state_entry()
    {
        vector vec = (vector) [1, 2, 3]; // ERROR : Type mismatch
        llOwnerSay((string) vec);
    }
}

ERROR: Syntax error

The compiler complains of a "syntax" error when it doesn't like your spelling, when it doesn't like your punctuation, or it thinks you typed too much script.

How much script is too much script never should but sometimes actually does vary by operating system. Linux, Mac OS X, and Windows reported different limits in 2007-08, so at that time you could run a script that you cannot edit without switching operating systems.

For example, once upon a time, Mac OS X could compile twenty-five cascaded else-if's, and Windows could not:

demoElseIfSyntaxError(integer count)
{
    if (count == 0)
    {
        ;
    }
    else if (count == 1)
    {
        ;
    }
    else if (count == 2)
    {
        ;
    }
    ...
    else if (count == 25)
    {
        ;
    }
}

Note: In effect, an astonishing compiler bug of this kind is a copy-restriction mechanism, preventing only people who have the buggy compiler from editing the source.