Results 1 to 5 of 5

Thread: Workaround for multidimensional arrays? (Pascal Script)

  1. #1

    Workaround for multidimensional arrays? (Pascal Script)

    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:
    Code:
    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?

  2. #2
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Workaround for multidimensional arrays? (Pascal Script)

    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.

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

    Your LandSize will be the same as LandWidth * LandHeight...
    Jason McMillen
    Pascal Game Development
    Co-Founder





  3. #3

    Workaround for multidimensional arrays? (Pascal Script)

    Quote Originally Posted by WILL
    Fixed
    [pascal]for i := 0 to LandSize - 1 do
    begin
    GetY := i div LandWidth;
    GetX := i mod LandWidth;
    end;[/pascal]
    And also the opposite:
    [pascal]
    for y := 0 to LandHeight - 1 do
    for x := 0 to LandWidth - 1 do
    begin
    tile[x+y*LandWidth]:=SomeValue;
    end;[/pascal]

  4. #4

    Workaround for multidimensional arrays? (Pascal Script)

    Thanks so much guys for pushing me into the right direction, it works like a charm now

  5. #5

    Workaround for multidimensional arrays? (Pascal Script)

    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...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •