Syntax

OSL programming is made up of 6 different types of syntax.

Commands

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.

command input1 input2 input3...
// Moves the "draw cursor" to the origin of the screen.
goto 0 0

// Outputs the draw cursor's new location to the JavaScript console.
log x_position y_position

Assignments

As the name suggests, assignments apply a value to the specified variable. The second token in an assignment will always be an assignment operator, 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.

variable assignment input
// Sets variable "var" to 10.
var = 10

// Inputs can also be previously defined variables.
varTwo = var
log varTwo

Operators

Operators return a value based on a calculation. Operators can either be equations (addition, subtraction, division, etc.), comparisons (==, <, >, etc.) or logic gates (and, or, nor, etc.). Unless parentheses are used, operators will always be processed from left to right, ignoring mathematical order of operations.

Methods

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.

Functions

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 null. Similarly to methods, functions can be run on their own, however no values will be modified.

Statements

Statements are containers for other commands, and modify their behavior through looping the statement or ignoring it if the specified conditions aren't met. 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.

Getting Started

Below are some helpful pages to learn more about:

Last updated

Was this helpful?