Well first, that isn't the Squirrel manual, Electric Imp has products that use squirrel language to program their products. It's a much simpler walk-through than the Squirrel documentation, but not everything you see there will work in AM.
I'm not sure if this is an AttractMode thing or a squirrel thing (maybe that's just a typo) but in AM the array function requires a size, so:
local myArray = array(5)
myArray[4] = "five"
Alternatively, you can just use:
local myArray = []
Also, remember arrays index start at zero.
Here's a few examples:
local myArray = []
myArray.push("An item")
print("First myArray item: " + myArray[0] + "\n")
local myDefinedArray = [ "Item One", "Item Two" ]
print("First myDefinedArray item: " + myDefinedArray[0] + "\n")
local fixedSizeArray = array(5)
fixedSizeArray[2] = "Item Three"
print("Third fixedSizeArray item: " + fixedSizeArray[2])
Extra credit Arrays are nice, but squirrel also allows for tables (maps) where you can identify the objects which can be more useful than arrays in some situations:
local myTable = {
one = "Item One",
two = "Item Two"
}
print( myTable.one )
If you plan on using identifiers with spaces, the formatting has to change:
local myTable = {
"item one": "Item One",
"item two": "Item Two"
}
Another bonus is table items can also be table items, so you can do something like:
local settings = {
basic = {
red = 100,
green = 0,
blue = 100
},
alternate = {
red = 100,
green = 0,
blue = 0
}
}
myObject.set_rgb( settings.basic.red, settings.basic.green, settings.basic.blue )
However, tables don't store their items in the same order you define them, so if you start using foreach you have to keep that in mind. You can put table items in an array though:
local objects = [
{ msg = "One", x = 0, y = 0, width = 100, height = 20 },
{ msg = "Two", x = 0, y = 30, width = 100, height = 20 }
]
foreach( obj in objects )
fe.add_text( obj.msg, obj.x, obj.y, obj.width, obj.height )
So, if you just want to create objects and reference them with a name, you can use tables. If you need an order specific list, use arrays.