LSL 101/Compile Time Errors

From Second Life Wiki
Jump to navigation Jump to search
← Creating a Script ↑̲  LSL 101  ̲↑

Let's look more closely at what happens when you save a script. If all goes well, you will see the two lines

Compile successful!
Save complete

in the pane below your script. These messages correspond to the two major steps that happen each time you save.

The first step is called compilation. The compiler is a part of SL that reads your script and translates it into a form that can be executed by SL. (Specifically, it is executed by a sim's server.) In order for the compiler to do this translation, your script has to be perfect from a grammatical point of view. If it comes across an error, the compiler will stop and give you an error message. In some cases, you'll see immediately what your mistake is. But the error messages aren't nearly as specific as they might be, so sometimes you'll have to scratch your awhile before you figure out what is wrong. In order to give you a head start, we'll look at some examples here.

Let's start with the basic new script that SL creates. <lsl> default {

    state_entry()
    {
         // Let the object's owner know the script is working
         llOwnerSay( "Congratulations! Your script has started to execute." );
    }

    touch_start( integer num_detected )
    {
         // Let the object's owner know the script is working
         llOwnerSay( "I've been touched!" );
    }

} </lsl> Suppose that in typing this in, instead of the { on the beginning of the second line, we type a (. When we save the script, instead of getting "Compile successful!", we get the message

(1, 0) : ERROR : Syntax error

What the compiler is saying here is that there is a syntax error at line number 1, position 0. (Remember what we said about programmers counting from 0 instead of 1.) So it is telling you that the parenthesis isn't legal. Unfortunately, what it doesn't tell you is what should be there. In this case, the only legal continuation after default is a left curly brace, so it could have said that. But the LSL compiler is pretty dumb, and as a scripter, you have to patient with it.

Let's take another example. Fix up the curly brace and then remove the semicolon at the end of line 5. Press the Save button again. This time, you'll get the message


(6, 5) : ERROR : Syntax error