Hello, world! *snickers* I have recently rejoined SL after a bit of a hiatus; I unfortunately had to transfer to a new account as I've lost access to my previous one, and even if I got it restored my inventory would be missing due to it being a TSL account. Anyways, I haven't LSL Scripted- or done any programming/coding/scripting, for that matter- in roughl 3-4 years. I'm trying to get back into it, and I figured LSL would be a great way to as I can immediately compile my codes into a visual result. I've been working on a script, and have reached a bit of difficulty within it. What I'm trying to create is a script where an object is black; upon clicking, it's starts cycling through a rainbow; upon clicking again, it returns to black; and on another click, it resumes its rainbow cycling. My issue is that, within the following code, the color changing can start just fine; however, due to the script being stuck in multiple while loops, it never allows me to touch it again to revert to black. Here's the code: //TRISTAN MAKE PRETTY COLOR CHANGING SCRIPT! YAYYY
//HI PERSON READING MY SCRIPT!
float red = 0.0;
float green = 1.0;
float blue = 0.0;
integer touched = FALSE;
default
{
state_entry()
{
llSetColor(<0, 0, 0>, ALL_SIDES);
llSetText("Touch to Start Color Cycle!", <1,1,1>, 1);
}
touch_start(integer detectednum)
{
if(touched == FALSE)
{
touched = TRUE;
llSetText(" ", <1,1,1>, 0);
llSetColor(<red, green, blue>, ALL_SIDES);
}
else
{
touched = FALSE;
llSetColor(<0, 0, 0>, ALL_SIDES);
llSetText("Touch to Start Color Cycle!", <1,1,1>, 1);
}
while(touched == TRUE)
{
//Becomes Red
while(red < 1)
{
red = (red + .01);
llSetColor(<red, green, blue>, ALL_SIDES);
llSleep(0.005);
}
while(green > 0)
{
green = (green - .01);
llSetColor(<red, green, blue>, ALL_SIDES);
llSleep(0.005);
}
//Becomes Pink
while(blue < 1)
{
blue = (blue + .01);
llSetColor(<red, green, blue>, ALL_SIDES);
llSleep(0.005);
}
//Becomes Blue
while(red > 0)
{
red = (red - .01);
llSetColor(<red, green, blue>, ALL_SIDES);
llSleep(0.005);
}
//Becomes Teal
while(green < 1)
{
green = (green + .01);
llSetColor(<red, green, blue>, ALL_SIDES);
llSleep(0.005);
}
//becomes Green
while(blue > 0)
{
blue = (blue - .01);
llSetColor(<red, green, blue>, ALL_SIDES);
llSleep(0.005);
}
//Cycles
}
}
} Now, I know I could use timers and a function to make this script work, but that would require calculation of color changing times; and I'm not doing this for the sake of making a color changing object, but rather for the sake of refreshing my mind on LSL and programming logic in general. What I'm looking for is a way that I could run what's in the while(touched == TRUE) loop, but still be able to use a touch_start to stop the loop at any time, not within a specific window of time. Would you mind sharing any ideas on how I could go about this? Thanks! ~Tristan Euclase