OSL ‐ Variables - Flufi-Boi/Origin-OS GitHub Wiki

Variables can be set and modified in quite a few ways, each of these doing something different:

Value assignment

a variable can be set to a value (can be any data type e.g. string, number, bool):

coins = 5

For example this sets "coins" to 5

Arrays

arrays (otherwise known as lists) can also be set in a couple of ways:

myarray = ["item1","item2"]

or

myarray = [
  "item1",
  "item2"
]

And both produce the same value.

Objects

Objects (json objects) are very similar to arrays, but having a key and value:

fruit_amounts = {"bananas":5,"apples":2}

and

fruit_amounts = {
  "bananas":5,
  "apples":2
}

Item assignment

Arrays

Array items can be set in a few ways:

myarr.[index] = value
myarr[index] = value
arr.item(index) = value

Objects

Very similar to arrays:

myobj[key] = value
myobj.[key] = value
myobj.key(key) = value
myobj."key" = value; // "key" has to be a string and cant be a variable.

Arithmetic Modifiers:

Just a fancy way of saying maths

  • variable += number

    • (strings) adds the number to the end of the text.
    • (number) increases the variable by the number
  • variable -= number

    • decreases the variable by the number
  • variable *= number

    • (strings) repeats the string x amount of times (e.g. "hello! " * 5 will output "hello! hello! hello! hello! hello! ")
    • (number) multiplies the variable by the number
  • variable /= number

    • divides the variable by the number
  • variable %= number

    • mods the variable to the number (mod is short for modulus)