Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Color change script problems

Shippou Oud
The Fox Within
Join date: 11 Jul 2005
Posts: 141
07-12-2007 08:24
Been tinkering with this for a while, and it does not loop the way it was ment to, any ideas on problem?
CODE

integer x;
float ct = .1;
float cr = .1;
default
{
state_entry()
{
llSetColor(<0,0,0>,ALL_SIDES);
state one;
}
}
state one
{
state_entry()
{


integer pick = (integer)llFrand(4);
if (pick == 4)
{
pick = 3;
}
if (pick == 0)
{
pick = 1;
}

if (pick == 1)
{
for (x=1; x!=11; x++)
{

llSleep(ct);
float red1;
red1 = red1 + cr;
llSetColor(<red1,0,0>,ALL_SIDES);
if (red1 == .9)
{
red1 = 0;
state default;
}
}}
if (pick == 2)
{
for (x=1; x!=11; x++)
{
llSleep(ct);
float blue1;
blue1 = blue1 + cr;
llSetColor(<0,0,blue1>,ALL_SIDES);
if (blue1 == .9)
{
blue1 = 0;
state default;
}
}}
if (pick == 3)
{
for (x=1; x!=11; x++)
{
llSleep(ct);
float green1;
green1 = green1 + cr;
llSetColor(<0,green1,0>,ALL_SIDES);
if (green1 == .9)
{
green1 = 0;
state default;
}
}}
}
}


Ynot Fenua
Registered User
Join date: 11 Oct 2006
Posts: 18
Can you explain
07-12-2007 08:46
Can you maybe explain what this script is meant to do, and what it actually is doing - and we might stand a chance of working out why it does not work.

As a general hint - a good way of debugging is lots of llOwnerSay messages - so you can trace the flow of the script.
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
07-12-2007 08:53
Hmmm... several problems here, but the looping problem is likely caused by using a "==" comparison on floats. Where there's something like "if (green1 == .9)..." probably something like "if (green1 >= 0.95)..." would help.

Would just also mention that "pick" is gonna be 1 twice as often as it's either 2 or 3. Probably something like "integer pick = (integer)llFrand(3.0) + 1;" is more what's intended.
Shippou Oud
The Fox Within
Join date: 11 Jul 2005
Posts: 141
07-12-2007 08:57
** All fixed** Problem with the loop was I had a float as a local float, and changing it's values in the wrong place, as far as the color, changing the wring value. It works, now to figure out something extra. =-)