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

LSL Wiki : ExampleStates

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.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
There are 3 comments on this page. [Display comments/form]