Data Containers
This tutorial will walk you through the 3 main containers available through the bot: Array, Map and SMap.
Array
The array works almost the same as in other languages. It is capable of being dynamically added to up to 1000 elements to prevent bot abuse.
Creating an array is done as follows:
It’s also possible to iterate over them using range
.
Since arrays are dynamic, it’s also possible to append one or more values to an existing array. An important thing to keep in mind is that while an array will try to use existing space to append new elements, if it runs out of space it will perform a resize+copy and return a new array. For this reason, it’s important to capture the return value of .Append
. Here is an example of some code that appends multiple values to the array and then prints the array and its length.
With an existing array, it’s possible to create a slice of the array. When created, a slice is a view into the original array with a modified start and/or end.
Map and SMap
Both map and smap are associative containers. The only difference is that map allows for its keys to be any comparable type, whereas smap only allows its keys to be strings. Maps and smaps also internally modify their structure and do not return copies when they run out of space, unlike arrays/slices of arrays. Like arrays, they are limited to 1000 elements to prevent bot abuse.
Creating a map is done as follows:
Iterating over the map/smap can be done with range, only this time it returns both the key and value.
Adding and removing elements can be done with .Insert
and .Remove
.
Contains
Arrays and Maps/SMaps can all be searched using the contains
function. This function is not a member of the types themselves, so you have to pass in the container as an argument.