- Joined
- Mar 3, 2006
- Messages
- 1,564
Is it possible to make more than 2D array variables and how far can you go ?
struct My3D
integer array var[10][20]
static method operator [] takes integer x return thistype
return thistype(x)
endmethod
endstruct
set My3D[1].var[2][3] = 42
// or without the method operator : set My3D(1).var[2][3]
Now if you really want N-D array, then it will probably better to use a custom function.
Which N-dimension do you want to use ?
As long as the demensions have a constant size you can use mathematics to emulate a nD array.
A 3D array formula...
x*ymax*zmax + y*zmax + z
library Var4D
globals
private integer array Size
endglobals
struct Var
private static constant integer A = 10
private static constant integer B = 2
private static constant integer C = 30
private static constant integer D = 4
private static integer index
integer int
static method operator [] takes integer x returns thistype
set thistype.index = 0
return thistype(x*thistype.B*thistype.C*thistype.D)
endmethod
method operator [] takes integer x returns thistype
local integer i
set thistype.index = thistype.index+1
set i = thistype.index
loop
exitwhen i >= 3
set i = i+1
set x = x*Size[i]
endloop
return thistype(this + x)
endmethod
static method onInit takes nothing returns nothing
set Size[0] = thistype.A
set Size[1] = thistype.B
set Size[2] = thistype.C
set Size[3] = thistype.D
endmethod
endstruct
endlibrary
set Var[9][1][29][3].int = 42