I have 16-element global arrays as follows:
var List ArraySun = newArrayList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
var List ArrayMon = newArrayList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
var List ArrayTue = newArrayList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
var List ArrayWed = newArrayList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
var List ArrayThu = newArrayList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
var List ArrayFri = newArrayList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
var List ArraySat = newArrayList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
and one 2-dimensional array (is this the correct syntax?)
var List ArrayWeek = newArrayList(ArrayMon, ArrayTue, ArrayWed, ArrayThu, ArrayFri, ArraySat, ArraySun) // is this the correct way to create an array of arrays?
In my rules I write and read the 1-Dimensional arrays via .set and .get as follows:
MyNumber = (Sunday.state as Number).intValue
ArraySun.set(MyIndex, MyNumber)
and
MyNumber = ArraySun.get(MyIndex)
etc.
Now I would like to read individual elements from the 2-dimensional array while inside 2 loops:
MyDay = 0
MyIndex = 0
while (MyDay < 7) {
while (MyIndex < 16) {
MyNumber = ArrayWeek.get(MyDay, MyIndex) // is this correct ?
MyArray = ArrayWeek.get(MyDay) //or do I need to do something
MyNumber = MyArray.get(MyIndex) // like this
logInfo(“Array Test”, ">>>>> RUNNING RULE = Array Test. MyNumber = " + MyNumber)
MyIndex = MyIndex + 1
}
MyDay = MyDay + 1
}
Can someone help me with the correct method and syntax to CREATE the 2-Dimensional array, ie. is “var List ArrayWeek = …” correct?
And with the correct method and syntax to READ individual elements from the 2-dimensional array?
And if I need in the future, the correct method and syntax to WRITE individual elements from the 2-dimensional array?
Thanks in advance…bob