SRL Archive - FAQ

constant multidimensional array


mattman709

2011-05-11 21:02:37

I've been trying to get a constant 2D array for tree colors. I've been able to do it roundaboutly by something along these lines:

var treeColors:array of array of integer;
procedure declareTrees();
var tree, oak, willow, maple, yew: array of integer;
begin
tree:=[0, 0, 0]; //has colors in it, just don't have script up ATM
//does the same for the other four
treeColors:=[tree, oak, willow, maple, yew];
end;

things that I've tried but fail and I'd like to know if I'm just doing it wrong:

treeColors:=[[0, 0, 0], [0, 0, 0]];
//inside of procedure

const treeColors:array of array of integer=[[0, 0, 0], [0, 0, 0]];
const tree:array of integer=[0, 0, 0];
//outside of procedure

Sex

2011-05-11 21:08:26

You can't have arrays as constants afaik.
Try this?
program new;
var
IntArr : T2DIntegerArray;
begin
IntArr := [TIntegerArray([0,1,2]), TIntegerArray([3,4,5])];
end.

NCDS

2011-05-11 21:39:56

From: Sex
You can't have arrays as constants afaik.
Try this?
program new;
var
IntArr : T2DIntegerArray;
begin
IntArr := [TIntegerArray([0,1,2]), TIntegerArray([3,4,5])];
end.

This. When using 2DArrays you need to declare the arrays inside the "main" array.