PDA

View Full Version : Workaround for multidimensional arrays? (Pascal Script)



Senap
08-06-2008, 03:35 AM
Hi!

I started writing a Civilization I clone but quickly hit a problem with the map generation process. I was thinking about using RemObjects Pascal Script to allow for different map generation scripts.

In Delphi, I'm using a simple multidimensional array like this:

TMap = record
Tiles: array[0..255,0..255] of TTile;
end;

Pascal Script gives me errors when I try to compile a multidimensional array. Normal arrays work so I guess that it simply doesn't support them. Do you have any ideas for a workaround?

WILL
08-06-2008, 07:11 AM
well did you know that your texture/video memory is really just a single dimension array even though you obviously can see it in 2 dimensions?

Make it a single dimension array and use simple math to detect your current X/Y location in the map.

ie.

for i := 0 to LandSize - 1 do
begin
GetY := (i div LandWidth) - (i mod LandWidth);
GetX := i - (GetY * LandWidth);
end;

Your LandSize will be the same as LandWidth * LandHeight...

User137
08-06-2008, 08:36 AM
Fixed :P
for i := 0 to LandSize - 1 do
begin
GetY := i div LandWidth;
GetX := i mod LandWidth;
end;


And also the opposite:

for y := 0 to LandHeight - 1 do
for x := 0 to LandWidth - 1 do
begin
tile[x+y*LandWidth]:=SomeValue;
end;

Senap
08-06-2008, 12:05 PM
Thanks so much guys for pushing me into the right direction, it works like a charm now 8)

harrypitfall
27-07-2008, 09:31 PM
I believe that a object is much better to expose the data to script.

I use IActiveScript JavaScript with delphi, and most of the data is exposed in objects.

TMapCell = Class(TPersistent);

TMap = Class(TPersistent)
Public
Procedure SetMapBounds(aWidth, aHeight: Integer);
Function GetMapCell(aCol, aRow: Integer): TMapCell;
End;

just a small sample, and helps when you need to expand information in every cell or on the map...