Don't click here unless you want to be banned.

LSL Wiki : ExampleStates

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ia360925.us.archive.org
This should help you understand how multiple states work.

// States in LSL example by Jim Bunderfeld

integer x = 0;

default
{
    touch_start(integer total_number)
    {
        if (x == 0)
        {
            llSay(0,"Chakra System Engaged");
            x = 1;
            llSleep(0.5);
            state k; // change to state k.
        }
    }
}
        
state k
{
    touch_start(integer total_number)
    {
        if (x == 1)
        {
            llSay(0,"Chakra System Disengaged");
            x = 0;
            state default; // change to default.
        }
    }
}

Unless you have some other use for variable x in this example, it is redundant and potentially confusing. You're using x to keep track of the "current system state", yet that is the purpose (and actual use here) of the state machine. You could easily get rid of all references to x in this example, making the example much simpler, clearer and a proper use of the state machine.
See ExampleStatesConcise for a clearer example.


Examples / States
Comments [Hide comments/form]
Added integer declaration for x at top of example. Removed declaration of unreferenced integer variable foo from top of example.
-- ChromalBrodsky (2004-04-26 16:24:20)
Thanks, Chromal. I thought I got them all.

Jim, in future, if you want to contribute an example, can you show it to me first? I'm all for more contributors, but we need the code to actually be valid.
-- CatherineOmega (2004-04-26 16:32:00)
(I don't want you to think of that as specifically me dumping on you, just that I want everyone to have someone else look over their code before you post it.)
-- CatherineOmega (2004-04-26 16:32:57)
Attach a comment to this page: