YENGswitch

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
Line 35: Line 35:
 
       break;
 
       break;
 
     }
 
     }
 +
    default: llOwnerSay ("dont know how to handle " + command);
 +
}<br>
 +
 +
other
 +
 +
switch (command)
 +
{
 +
    case 4:
 +
        llSay(0, "4");
 +
        break;
 +
    case 5 ... 20:
 +
      llSay(0, "5 to 20");
 +
      break;
 +
 +
    case 22:
 +
    case 27:
 +
      llSay(0, "other");
 +
      break;
 +
 
     default: llOwnerSay ("dont know how to handle " + command);
 
     default: llOwnerSay ("dont know how to handle " + command);
 
  }
 
  }

Revision as of 16:18, 19 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(0, "4");
        break;
    }
    case 5 ... 20:
    {
      // ... defines a range
      llSay(0, "r");
      break;
    }
    default: llOwnerSay ("dont know how to handle " + command);
}

other

switch (command)
{
    case 4:
        llSay(0, "4");
        break;
    case 5 ... 20:
      llSay(0, "5 to 20");
      break;
    case 22:
    case 27:
      llSay(0, "other");
      break;
    default: llOwnerSay ("dont know how to handle " + command);
}
Personal tools
General
About This Wiki