Skip to main content
Most variables hold one thing, like a number. Sometimes you need many things in one box. That’s what Collections and Objects are for.

Collection

A list, like a shopping list.sword, shield, potion

Object

A card with labelled boxes, like settings.prefix: !, color: #F5C842
New to all this? You can build almost everything with Number, Text and User variables. Come back to Collections and Objects when you feel ready.

Collections (lists)

A Collection is a list, like a shopping list:
Use a Collection for things like a list of bad words, a list of prizes, a list of people who joined a giveaway, or a shop. Each thing in the list is an item. Items can be plain words, or they can have keys, like a shop where each item has a name, a price and a stock:

Change a list with Save a value

Pick a Collection variable in the Save a value block and you get a Collection Operation menu:

Read a list

In .each[...], $value is the thing, $number counts 1, 2, 3, and $name, $price (any key) read that key of the item. \n means a new line.
Watch the places. In Save a value (Set value at position, Remove value at position) the first place is 1. When you read with {DBVAR_bag.0}, the first place is 0.
Want to do something for every item, like give each one a button? Use the Repeat block with Each item in a list. While it runs, {item} is the current item and {loop_number} is which turn it is on. See Repeats and waiting.

Objects (named keys)

An Object is like a card with labelled boxes on it. Each box has a name (a key) and holds something:
Perfect for settings, profiles, shops and inventories. Instead of making three variables, you make one and keep everything together.

Change an object with Save a value

In Save a value, pick an Object variable and choose an Object Operation: The block on the canvas then says what it does, for example Remove shop.coins, so you can read your canvas at a glance.

Read a key

Put a dot and the key name after the variable:

Starting properties

When you make an Object variable (or a User variable that stores an Object), you can add Starting properties: the named values every new entry begins with. Press Add property to add one. For example, add coins = 0, gems = 0 and title = Newbie. Now every new member starts with exactly those boxes filled in. You can set Starting properties in the builder’s Create New Variable window and on the Database page.

Objects for every member

A User variable can also store an object, so each member has their own card, like {DBVAR_pet.name} and {DBVAR_pet.happiness}. In Save a value or Do the maths, fill in the Key box to change just one part.

Example: a tiny shop

1

Make the variable

Make a Collection variable called shop.
2

Fill it

In a Save a value block, pick shop, choose Add item and write name=Potion, price=50.
3

Show it

In /shop, add a Reply with:
For the full buy-and-sell version, see A shop with items.