Collections
Last updated
Was this helpful?
Last updated
Was this helpful?
Collections or arrays are a special data storage 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 data.
Collection values are stored on positions in the collection. Each position has it's own number to access it, starting at 0. Every value is seperated with a comma.
Collections also have default values you are able to set when creating or editing a variable in the data storage module.
Here are some examples of collection references and their values or arrays:
{BGVAR_collection}
- [hello, world, abc, xyz]
{valueAtPosition({BGVAR_collection}),[2]}
- abc
{lengthOfCollection({BGVAR_collection})}
- 4
Collection positions always start at 0.
To display values stored in the collection variable, you can target the position of the value. You can also use other variables to access the data in other ways. Below are some examples of targeting positions in the collection variable:
{BGVAR_collection}
- [hello, world, abc, xyz]
{valueAtPosition({BGVAR_collection}),[0]}
- hello
{valueAtPosition({BGVAR_collection}),[1]}
- world
{valueAtPosition({BGVAR_collection}),[2]}
- abc
This variable can be used anywhere in your command and event builder and will retrieve the corresponding value for the given position of the collection.
BotGhost offers some variables you can use for any array or collection (even from an API response), which allow you to retrieve specific information of the collection. To know more about them, check out the Variables page.
Targeting also works for collection variables, when they are user or channel specific. Just like regular variables, you can add the square brackets [] at the end of the base variable providing the user / channel target, for example:
{BGVAR_collection[user_id]}
{valueAtPosition({BGVAR_collection[user_id]}),[0]}
If no target is provided, the value of the user who triggered the last interaction (command, event, button or select menu) will be returned for user collections, or the value of the channel the last interaction has been triggered in (command, event, button or select menu) will be returned for channel collections.
To update a collection value, you can use one of the variable actions below:
Collection variables selected in this block will allow you to set a value somewhere in a collection.
This action block will allow you to delete a collection value.
You can not use the Run Equation on Variable action on collections.