For the complete documentation index, see llms.txt. This page is also available as Markdown.

Original Local Scoping (local / this)

This is the original originOS local-scoping page. It describes the old local keyword and this scope object, which are not part of the current OSL compiler.

About Variables

In osl all variables are global scope and to use locally scoped variables you must use the keyword local

Where can I use local?

You can local scope inside of any function context

How does local work?

The local keyword creates a key on an json object that's unique to the current context/scope that's accessible using the this keyword

local key = "1234"

log this
// returns {"key":"1234"}

this has a different value depending on the scope of when you access it

Local variables can be re-assigned without the local keyword

def myFunc() (
  local v = 0
  v ++
  return v
)

log myFunc()
// returns 1

Example script

If a local variable and a global variable exist with the same name, it will access the local variable first.

Last updated