Switch Case
Switch case is incredibly useful in osl due to its sheer speed when compared with an if else tree, along with its improved readability
Main Syntax
You encapsulate a switch case statement with a simple switch statement
Cases
You can add a simple case using the syntax shown below
Default
You can use the default case to handle when none of the cases are met.
It must be placed at the bottom of the switch case statement
Example shown below
Break?
You need to send your cases with break otherwise you may end up causing some big issues
When break is run, the switch case will immediately be exited
Advanced
Compiler
The compiler is a complex topic and this is not for beginners, but does help for developers to understand this
A simple switch case like the one below is converted by the compiler into jumps and equality checks
The compiler output for this script (origin v5.1.2) looks like this:
Comments have been added by me to help explain
Last updated