Like many programming languages, Experimentor supports the idea of a collection of items. Collections are very powerful and allow you to do all sorts of wonderful things.

Unlike many other programming languages, Experimentor collections are very easy to use while being simultaneously very powerful.

Defining a collection

Defining a collection is done in almost the same way as defining anything else in Experimentor:

There are however a few important difference when defining a collection of things and defining other types:

  1. There is no “without persistence” on a collection. Collections do not (currently) support any type of persistence, so indicating that you don’t want persistence on a collection is rather redundant.
  2. When defining the list of things inside a collection there are no define statements or assignment statements, just a list of values.

For example, let us define a collection of different colours:

Or perhaps define a collection of strings:

Notice that in all cases, we are not using the “define” keyword inside the collection – we are just providing a collection of data values.

Variables inside the collection definition

Of course, we can use variables inside our collection definition like so:

However – and this is a little tricky – these variables will not be “resolved” until the collection is actually created. That is, the data value inside the variable is not inserted into the list until you actually create a copy of the collection.

Creating shapes inside your collection

It’s also possible to create collections of objects (such as shapes, text or images).  For example, the following code creates a collection of sound objects:

The above program creates a collection of different shapes, and because they all had isVisible=true  the wait command on the last line will display all these shapes for 5 seconds.  (Note that without creating the collection using define shapes = create ShapesCollectionType  there wouldn’t be anything visible, because we would only have defined a type/template for a collection, but never have actually created such a collection).

Creating sounds inside your collection

It’s also possible to create collections of sounds; for example, the following code creates a collection of sound objects:

Creating your collection

Just like rectangles, circles, and devices, defining a collection does not actually create any copies of that collection – it just defines the collection “type”.

To actually create a collection instance that we can start doing things with we need to use the “create” keyword:

This gives us an actually instance of our “ColourCollectionType” collection definition inside the “colours” variable (“data bucket”). Now we can actually use our list to do interesting things.

Quickly creating an empty collection

It’s possible to use a short-cut to create a new empty collection, without first defining a collection type:

This allows you to then add items to the collection using the collection operators.