Syntax
Last updated
Was this helpful?
Last updated
Was this helpful?
OSL programming is made up of 6 different types of syntax.
Commands are the backbone of most OSL scripts— generally, any operation involving modifying the program's state is done through them. They accept multiple inputs after the initial command, seperated by spaces. These inputs can be constants, such as raw strings or numbers, operators (which are defined later), or variables. Commands have no return value.
As the name suggests, assignments apply a value to the specified variable. The second token in an assignment will always be an , usually taking the form of an equals sign (=). Assignments only take one input (aside from the initially specified variable), and do not have a return value.
Methods return a modified value based on a singular input. Methods can follow any constant or variable, and that value will act as it's input. Values inside the parentheses will act as parameters, although not every method will require those. In cases with multiple parameters, each value is seperated by a comma.
Methods don't necessarily need to be part of another statement. In cases where a method is isolated, the input will automatically be updated to the method's return value.
Below are some helpful pages to learn more about:
Operators return a value based on a calculation. Operators can either be (addition, subtraction, division, etc.), (==, <, >, etc.) or (and, or, nor, etc.). Unless parentheses are used, operators will always be processed from left to right, ignoring mathematical order of operations.
Functions are similar to methods, with the main difference being that functions do not take an input. Functions typically return a value, however this isn't strictly required— functions lacking an output won't throw an error, but instead output . Similarly to methods, functions can be run on their own, however no values will be modified.
Statements are containers for other commands, and modify their behavior through or . Statements are always followed by a set of parentheses which surround a script. They generally take one or more inputs, supplied between the statement itself and the opening parenthesis.