YENGswitch

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
m (Add into category)
m (Add pre html tag)
Line 2: Line 2:
 
break, default and '...' are keywords used with it.<br>
 
break, default and '...' are keywords used with it.<br>
  
simple string (command) example:
+
Simple string (command) example:
  
switch (command)
+
<pre>
{
+
switch (command)
    case "turnleft":
+
{
    {
+
    case "turnleft":
        TurnLeft ();
+
    {
        break;
+
        TurnLeft ();
    }
+
        break;
    case "turnright":
+
    }
    {
+
    case "turnright":
        TurnRight ();
+
    {
          break;
+
        TurnRight ();
    }
+
        break;
    default: llOwnerSay ("dont know how to handle " + command);
+
    }
}
+
    default: llOwnerSay ("Dont know how to handle " + command);
 +
}
 +
</pre>
  
a simple integer example
+
A simple integer example
 
... can be used to define a range
 
... can be used to define a range
  
switch (command)
+
<pre>
{
+
switch (command)
    case 4:
+
{
    {
+
    case 4:
        llSay(0, "4");
+
    {
        break;
+
        llSay(PUBLIC_CHANNEL, "4");
    }
+
        break;
    case 5 ... 20:
+
    }
    {
+
    case 5 ... 20:
      // ... defines a range
+
    {
      llSay(0, "r");
+
        // ... defines a range
      break;
+
        llSay(PUBLIC_CHANNEL, "r");
    }
+
        break;
    default: llOwnerSay ("dont know how to handle " + command);
+
    }
}<br>
+
    default: llOwnerSay ("Dont know how to handle " + command);
 +
}
 +
</pre>
  
other
+
Other:
  
switch (command)
+
<pre>
{
+
switch (command)
    case 4:
+
{
        llSay(0, "4");
+
    case 4:
        break;
+
        llSay(PUBLIC_CHANNEL, "4");
    case 5 ... 20:
+
        break;
      llSay(0, "5 to 20");
+
    case 5 ... 20:
      break;
+
        llSay(PUBLIC_CHANNEL, "5 to 20");
    case 22:
+
        break;
    case 27:
+
    case 22:
      llSay(0, "other");
+
    case 27:
      break;
+
        llSay(PUBLIC_CHANNEL, "other");
 
+
        break;
    default: llOwnerSay ("dont know how to handle " + command);
+
    default: llOwnerSay ("dont know how to handle " + command);
}
+
}
 +
</pre>
  
 
The different case ranges can not overlap.
 
The different case ranges can not overlap.
  
 
[[Category:Scripts]]
 
[[Category:Scripts]]

Revision as of 04:48, 22 September 2020

switch can only work in integer expressions, or strings
break, default and '...' are keywords used with it.

Simple string (command) example:

switch (command)
{
    case "turnleft":
    {
        TurnLeft ();
        break;
    }
    case "turnright":
    {
        TurnRight ();
        break;
    }
    default: llOwnerSay ("Dont know how to handle " + command);
}

A simple integer example ... can be used to define a range

switch (command)
{
    case 4:
    {
        llSay(PUBLIC_CHANNEL, "4");
        break;
    }
    case 5 ... 20:
    {
        // ... defines a range
        llSay(PUBLIC_CHANNEL, "r");
        break;
    }
    default: llOwnerSay ("Dont know how to handle " + command);
}

Other:

switch (command)
{
    case 4:
        llSay(PUBLIC_CHANNEL, "4");
        break;
    case 5 ... 20:
        llSay(PUBLIC_CHANNEL, "5 to 20");
        break;
    case 22:
    case 27:
        llSay(PUBLIC_CHANNEL, "other");
        break;
    default: llOwnerSay ("dont know how to handle " + command);
}

The different case ranges can not overlap.

Personal tools
General
About This Wiki