Hey @neku , I'm sorry I missed this thread for the last week! You might want to start a new thread when switching topics (e.g., talking about 2D arrays), so they are easier to spot.
As @shellrider and @jahnocli have both said, in MiniScript the only "2D Array" is a list of lists. In Mini Micro, you can import "listUtil"
, and then set up and use a 2D array like this (on the command line):
]import "listUtil"
]cb = list.init2d(8,8)
]cb = list.init2d(8,8, 0)
]cb[1][0]
0
]cb[1][0] = 999
]cb[1][0]
999
If you aren't using MiniScript, but are using something else like the Try-It! page, then you'll probably want to just add this handy init2D method yourself (by copying it from /sys/lib/listUtil.ms):
// init: build an array initialized with an initial value.
// Note that initialValue may be a function passed in with @
// (for example, @rnd), in which case it will be invoked for
// each element as they are created.
list.init = function(size, initialValue)
if @initialValue isa funcRef then
result = []
for i in range(1, size)
result.push initialValue
end for
return result
else
return [initialValue] * size
end if
end function
// init2d: build a 2D array, composed as a list of lists.
list.init2d = function(sizeA, sizeB, initialValue)
result = []
for a in range(1, sizeA)
result.push list.init(sizeB, @initialValue)
end for
return result
end function