OSL ‐ Arrays - Mistium/Origin-OS GitHub Wiki
About Arrays in OSL
Arrays in OSL are defined by []
and can contain elements of any length and any data type, allowing for flexibility in data structure.
Example array:
["Hello", "Wow", 100, {"huh": 10}]
Important
Indexes in OSL arrays start at "1".
Commands
Defining an Array
To define an array, use the following syntax:
arrayName = ["element1", "element2", ...]
Example:
myArray = ["test", "data"]
Array Functions
-
.append("string")
:- Adds a new element (in this case, a string) to the end of an array.
- Example:
Results inmyArray = ["hi"] myArray.append("goodbye")
["hi", "goodbye"]
.
-
.index("string")
:- Finds the index of a specific element (string) in an array.
- Example:
myArray = ["hi", "goodbye"] index = myArray.index("hi")
index
now contains1
.
-
.delete(int)
:- Removes an element at a specific index from an array.
- Example:
Results inmyArray = ["hi", "goodbye"] myArray.delete(1)
["goodbye"]
.
-
.item(int)
or.[int]
or[int]
:- Retrieves the item at a specific index in the array.
- Example:
myArray = ["hi", "goodbye"] item = myArray.item(1) item = myArray.[1] item = myArray[1]
item
now contains"hi"
.
-
.join("string")
:- Combines all elements of an array into a single string, separated by the specified separator.
- Example:
myArray = ["hello", "how are you"] result = myArray.join(", ")
result
now contains"hello, how are you"
.
-
.split("string")
:- Splits a string into an array of substrings, separated by the specified separator.
- Example:
myString = "hello, how are you" resultArray = myString.split(", ")
resultArray
now contains["hello", "how are you"]
.
-
.insert(position, "string")
:- Inserts a new element (string) at a specified position in the array.
- Example:
Results inmyArray = ["apple", "banana", "cherry"] myArray = myArray.insert(2, "orange")
["apple", "orange", "banana", "cherry"]
. The string "orange" is inserted at position 2, shifting the subsequent elements to make room.