Collections
Last updated
Last updated
Collections or arrays are a special data type that allows you to store a group of text or numbers. Collections consist of an ordered list using numbered indexes starting from 0 to access specific items.
Some examples of collections or arrays:
[1,2,3,4,5]
[hello, one,two, three]
[]
[warning 1, warning 2]
In summary, collections allow you to store and access multiple pieces of information that relate to one entity. These could be used for warning systems, economy shops, inventories, giveaway entrants, and much more. A collection be server-specific, global, user-specific, or channel-specific like any other data type.
Collections have specific operations within the Set a Variable action block. These operations manipulate the collection in a certain way.
Pushes a value to the front of a collection.
Example: Pushing the value 'hello' to the start of the following collection.
Before: [1,2,3,4,5]
After: [hello,1,2,3,4,5]
Pushes a value to the end of a collection.
Example: Pushing the value 'hello' to the end of the following collection.
Before: [1,2,3,4,5]
After: [1,2,3,4,5,hello]
Removes a value from the start of a collection.
Example: Removing the value from the start of the following collection.
Before: [1,2,3,4,5]
After: [2,3,4,5]
Removes a value from the end of a collection.
Example: Removing the value from the end of the following collection.
Before: [1,2,3,4,5]
After: [1,2,3,4]
Sets or, if there's already a value in the provided position, replaces the value at a specific position in the collection.
Example: Set the value "hello" at position 1 in the following collection.
Before: [1,2,3,4,5]
After: [1,hello,2,3,4,5]
Collection positions always start at 0!
Removes the value at a specific position in the collection.
Example: Remove the value "hello" at position 1 in the following collection.
Before: [1,2,3,4,5]
After: [1,3,4,5]
Collection positions always start at 0!
Removes a specific value in a collection. Removes only the first occurrence of that value.
Example: Remove the value "1" from the following collection.
Before: [1,2,3,4,5,1]
After: [2,3,4,5,1]
Clears the entire collection and sets its value to [].
Example: Clear the following collection.
Before: [1,2,3,4,5]
After: []
Collections have specific function variables.
Variable | Explanation |
---|---|
{lowestValue({BGVAR_collection})}
Returns the lowest value in a collection
{highestValue({BGVAR_collection})}
Returns the highest numerical value in a collection
{lengthOfCollection({BGVAR_collection})}
Returns the length of a collection
{valueAtPosition({BGVAR_collection}),[2]}
Returns the value at a specific position in the collection. Positions start at 0.
{positionOfValue({BGVAR_collection}),[hello]}
Returns the position of a value.
{collectionCharacterLength({BGVAR_collection})}
Returns the total character length of a collection.
{printAllValues({BGVAR_collection}),[Hello $value]}
Prints all values in a collection. The text returned can be set in the [].
{getRandomFromCollection({BGVAR_collection})}
Returns a random value from the collection.