Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Getting errors...

Joey Blackrain
Registered User
Join date: 7 Feb 2010
Posts: 1
02-07-2010 13:56
Hey, I'm new to this forum, like, this is my first post, but I decided to get into scripting and hit a dead end so I need help. I tried the basic of basics, changing colors, but it's giving me an error I can't figure out. I'll post the script.

default
{
state_entry()
{
llSay(0, "Yes master. Turning on.";);
llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES);
}
state_entry
{
llSay(0, "Noted. Turning off.";);
llSetColor(<0.0, 0.0, 0.0>, ALL_SIDES) ;
}
touch_start( integer total_number)
{
state default;
}
}
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
02-07-2010 14:20
Ah... well.... Several errors, but it's a nice little script to start with and the errors are instructive.

First, you only have one state, the one called "default." That's normal. So, state default starts with the word "default" followed immediately by an open curly bracket, and it ends with a closed curly bracket. Everything else fits between, like so ...

CODE

default
{

//Everything else

}


Since you're in state default, you never have to go to it. So get rid of the line that says "state default;"

Next, you can only have one event of each kind in a state. You can't have two state_entry events. One has to go. A state_entry event is generally used to initialize variables that will be used later, or to set up handles for events like listen, sensor, timer, etc. You're not doing that, except maybe to set a "starting point" color for your object.

Third, the touch_start event is triggered by someone touching the object. The things you want to have happen need to be in that event. You don't have anything there now, so you'll need to move the color changing stuff to that event.

Finally, if you want to change color with each touch, you have to actually provide a switch to do that. You don't have one. A switch is basically an index variable that changes from positive to negative, or TRUE to FALSE, or whatever, each time you encounter it.

So... here's one way to repair your script..


CODE

integer Switch; // This is global variable, defined outside state default, initially == FALSE

default
{
state_entry()
{
llSetColor(<0.0, 0.0, 0.0>, ALL_SIDES); // A starting point
}

touch_start(integer num)
{
if (Switch == FALSE) // Object is black, so you want to make it white
{
llSay(0, "Yes master. Turning on.");
llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES);
}
else // Object is white, so you want to make it black
{
llSay(0, "Noted. Turning off.");
llSetColor(<0.0, 0.0, 0.0>, ALL_SIDES) ;
}
Switch = !Switch; // This reverses the sense of Switch from TRUE to FALSE or vice versa
}
}


There are certainly other ways to write this, and to do it more compactly, but I've left this sample wide open so you can see how the parts work.

Take a look at some of the scripting tutorials at the LSL wiki site http://wiki.secondlife.com/wiki/LSL_Tutorial for a more complete discussion of these things an others. Welcome to the wonderful world of LSL scripting.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at