OpenSim: LSL2CS: Difference between revisions

From OpenSimulator
Jump to navigationJump to search
imported>Steevithak
m cleaned up code spacing
imported>Djphil
m Indentation and syntax highlighting
 
Line 1: Line 1:
default {
<source lang="lsl">
    state_entry()
default
    {
{
    state_entry()
        integer i;
    {
        for( i=0; i<13;i++ )
        integer i;
        {
 
          llSay(0,(string)i);
        for(i = 0; i < 13; i++)
        }
        {
            llSay(PUBLIC_CHANNEL, (string)i);
    }
        }
}
    }
}
</source>


--- can be transformed to
--- can be transformed to


default {
<source lang="lsl">
    state_entry()
default
    {
{
      llSay(0,"started");
    state_entry()
    {
      integer i;
        llSay(PUBLIC_CHANNEL, "started");
      i=0;
 
      while( i<13 )
        integer i;
      {
        i = 0;
        llSay(0,(string)i);
 
        i++;
        while(i < 13)
      }
        {
      llSay(0,"finished");
            llSay(PUBLIC_CHANNEL, (string)i);
    }
            i++;
}
        }
 
        llSay(PUBLIC_CHANNEL, "finished");
    }
}
</source>


--- can be transformed to
--- can be transformed to


    void state_entry()
<source lang="CSharp">
    {
void state_entry()
{
      int i;
    int i;
      i=0;
    i = 0;
 
      SetScope( delegate()  
    SetScope(
          { return i<13; },  
        delegate()  
          delegate()  
        {
          {
            return i < 13;
            llSay(0,(string)i);
        }, delegate()
            i++;
        {
          }, delegate()
            llSay(PUBLIC_CHANNEL, (string)i);
          {
            i++;
            llSay(0,"finished");
        }, delegate()
          }
        {
      );
            llSay(PUBLIC_CHANNEL, "finished");
    }
        }
    );
}
</source>


---
---


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.
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.

Latest revision as of 17:54, 30 September 2020

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.