OSL ‐ Variables - Mistium/Origin-OS GitHub Wiki
Variable Assignment:
-
variablename = "assign-data":
-
Description: Sets a variable with the specified name (
variablename) to the inputted data ("assign-data"). -
Example:
count = 10This sets the variable
countto the value10. -
Example (Setting a variable to an array):
array = ["hello", "world"]or
array = [ "hello", "world" ]This sets the variable
arrayto the value["hello", "world"]. -
Example (Setting a variable to an object):
array = {"hello":"world"}or
array = { "hello":"world" }This sets the variable
arrayto the value["hello", "world"].
-
-
variable,variable = array:
-
Description: Sets a group of variables to an array's contents.
-
Example:
array = [ "item1", "item2" ] var1,var2 = arrayThis sets var1 to "item1" and var2 to "item2"
array = [ "item1", "item2", "item3" ] var1,var2 = arrayThis will also work, aswell as any other variable assigment.
-
Example (Embedded assigment):
array = [ "item1", "item2", "item3" ] array2 = [ "otheritem1", "otheritem2" ] array2[1],array2[2],var = arrayThis both sets array2's first and second item while setting
varto "item3"
-
List Item Assignment:
-
list.[itemnumber] = "assign-data":
- Description: Sets the selected item of a list (specified by
[itemnumber]) to the inputted data ("assign-data"). - Example:
This sets the third item in the listmylist.[3] = "new_value"mylistto the value"new_value".
- Description: Sets the selected item of a list (specified by
-
list[itemnumber] = "assign-data":
- Description: Same functionality as list.[itemnumber].
- Example:
This sets the third item in the listmylist[3] = "new_value"mylistto the value"new_value".
JSON Object Key Assignment:
-
object.key("key") = "assign-data":
- Description: Sets the selected key of a JSON object (specified by
"key") to the inputted data ("assign-data"). - Example:
This sets the value associated with the keymyobject.key("name") = "John""name"in the JSON objectmyobjectto"John".
- Description: Sets the selected key of a JSON object (specified by
-
object.key = "assign-data":
- Description: Sets the selected key of a JSON object (specified by
key) to the inputted data ("assign-data"). - Example:
This sets the value associated with the keymyobject.name = "John"namein the JSON objectmyobjectto"John".
- Description: Sets the selected key of a JSON object (specified by
-
object."key" = "assign-data":
- Description: Sets the selected key of a JSON object (specified by
"key") to the inputted data ("assign-data"). - Example:
This sets the value associated with the keymyobject."name" = "John""name"in the JSON objectmyobjectto"John".
- Description: Sets the selected key of a JSON object (specified by
-
object.["key"] = "assign-data":
- Description: Sets the selected key of a JSON object (specified by
"key") to the inputted data ("assign-data"). - Example:
This sets the value associated with the keymyobject.["name"] = "John""name"in the JSON objectmyobjectto"John".
- Description: Sets the selected key of a JSON object (specified by
-
object["key"] = "assign-data":
- Description: Sets the selected key of a JSON object (specified by
"key") to the inputted data ("assign-data"). - Example:
This sets the value associated with the keymyobject["name"] = "John""name"in the JSON objectmyobjectto"John".
- Description: Sets the selected key of a JSON object (specified by
Arithmetic Modifiers:
-
variable += 10:
- Description: Appends ten to the end of a string or adds ten to a number data type.
- Example:
This increments the value of the variablecount += 5countby 5.
-
variable *= 5:
- Description: Sets the variable to itself multiplied by 5. This operation works only on number data types.
- Example:
This doubles the value of the variabletotal *= 2total.
-
variable /= 5:
- Description: Sets the variable to itself divided by 5. This operation works only on number data types.
- Example:
This halves the value of the variableprice /= 2price.
-
variable -= 5:
- Description: Sets the variable to itself minus 5. This operation works only on number data types.
- Example:
This subtracts 10 from the value of the variablebalance -= 10balance.
-
variable %= 5:
- Description: Sets the variable to itself mod 5. This operation works only on number data types.
- Example:
This does a modulus calculation on the value ofbalance %= 10balance.
These commands and modifiers enable you to manipulate variables, lists, and JSON objects, performing assignments and arithmetic operations as needed in your script.