HyperScript
Docs

← All of the Docs The basics

Switch

Guide and examples

switch runs one block out of several, chosen by a value. It reads better than a chain of else if when a command has many subcommands:

switch arg.1:
    case "on", "enable":
        set {event_active} to true
    case "off", "disable":
        set {event_active} to false
    default:
        send "&eUsage: /event <on|off>"
  • The first case with a matching value runs, and only that one; there is no falling through.
  • A case may list several values, separated by commas. Text is compared ignoring case, as == does.
  • case 1 to 5: is every number from the one to the other, both included, and can stand in a list with others: case 1 to 5, 10, 20 to 30:.
  • default: runs when nothing matched. It is optional.