Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Silly basic problem

Tegg Bode
FrootLoop Roo Overlord
Join date: 12 Jan 2007
Posts: 5,707
08-03-2008 01:31
Hi, I haven't written much code since VIC20/C64 days so call me a noob to LSL/C++
I wrote this little script to toggle something between 3 states, but I am getting 4 states somehow, unless I put command to -1 it doesn''t work at all.

integer command;
integer channel=55500;

default
{
state_entry()
{
}
touch_start(integer tn)
{
command=command+1;
llWhisper(0,"Command "+(string)command);
if(command==0)
{
llSetLinkAlpha(LINK_ALL_CHILDREN, 0.0, ALL_SIDES);
llSetLinkPrimitiveParams(LINK_ALL_CHILDREN,[PRIM_SIZE,<0.01,0.01,0.01>]);
}

if(command==1)
{
llSetLinkAlpha(LINK_ALL_CHILDREN, 1.0, ALL_SIDES);
llSetLinkPrimitiveParams(2,[PRIM_SIZE,<0.1,0.1,0.11>]);
llSetLinkPrimitiveParams(3,[PRIM_SIZE,<0.1,0.1,0.1>]);
llSetLinkPrimitiveParams(4,[PRIM_SIZE,<0.07,0.06,0.03>]);

}
if(command==2)
{
llSetLinkPrimitiveParams(5,[PRIM_SIZE,<0.03,0.01,0.3>]);
}
if(command==3)
{
command=-1;
}
}
}
_____________________
Level 38 Builder [Roo Clan]

Free Waterside & Roadside Vehicle Rez Platform, Desire (88, 17, 107)

Avatars & Roadside Seaview shops and vendorspace for rent, $2.00/prim/week, Desire (175,48,107)
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
08-03-2008 01:58
the variable: 'command' gets no initial value:(
Try a command=0; // in state_entry() of the default state
and see if that works:)
_____________________
From Studio Dora
Georg Stonewall
Husband of Nikki
Join date: 21 Jan 2007
Posts: 211
08-03-2008 02:03
G'day Tegg,

0 to 3 are 4 states, or?
But anyway, I would set the command value in the state_entry, so after a reset of the script it will start from the beginning.

state_entry()
{
command = -1;
}

Then I would use *else if* instead of separat *if*

Last but not least i would ask for *command > 2* instead of *command == 3*
If command becomes 4 for some reason, then the script would not work anymore until you restart it.

Hope that helps a little.
_____________________
G&N Quality Design


SLURL

Blog

Flickr

XStreetSL
Tegg Bode
FrootLoop Roo Overlord
Join date: 12 Jan 2007
Posts: 5,707
08-03-2008 02:50
Cool, thx guys that got me on the right track, thought it was something silly :)
_____________________
Level 38 Builder [Roo Clan]

Free Waterside & Roadside Vehicle Rez Platform, Desire (88, 17, 107)

Avatars & Roadside Seaview shops and vendorspace for rent, $2.00/prim/week, Desire (175,48,107)