OpenSim: LSL2CS

From OpenSimulator
Revision as of 17:54, 30 September 2020 by imported>Djphil (Indentation and syntax highlighting)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
default
{
    state_entry()
    {
        integer i;

        for(i = 0; i < 13; i++)
        {
            llSay(PUBLIC_CHANNEL, (string)i);
        }
    }
}

--- can be transformed to

default
{
    state_entry()
    {
        llSay(PUBLIC_CHANNEL, "started");

        integer i;
        i = 0;

        while(i < 13)
        {
            llSay(PUBLIC_CHANNEL, (string)i);
            i++;
        }

        llSay(PUBLIC_CHANNEL, "finished");
    }
}

--- can be transformed to

void state_entry()
{
    int i;
    i = 0;

    SetScope(
        delegate() 
        {
            return i < 13;
        }, delegate()
        {
            llSay(PUBLIC_CHANNEL, (string)i);
            i++;
        }, delegate()
        {
            llSay(PUBLIC_CHANNEL, "finished");
        }
    );
}

---

In the above code, the engine will test the condition and call the 'current scope' until the condition is false, then it will set current scope to null and run the third delegate.