• Log in or sign up for an account here: https://www.sythe.org/login

2D array?

v4mp1r3-2

Newcomer
Joined
Jan 10, 2006
Sythe Gold
0
Messages
5
Hey, I've programmed in pascal before, a lot, just moved to SCAR trying to make a simple script, but when I tried to define a 2D array it returned an error...
The line of code is:

Code:
Grid = array [0..7, 0..7] of Integer;

And it returns the error:

Code:
Line 4: [Error] (4:19): Closing square bracket (']') expected in script ../

Any help?
 
Try this:

Code:
Grid : Array[0..7] of Array[0..7] of Integer;

The declarations are a bit different in scar. Shoot me a pm or add me on MSN if you need some more help!

~Sandstorm
 
Thanks, I'll test it now

EDIT: Now I'm getting Grid is an unknown type errors. :(

Code:
program Code;

type
    //Grid = array [0..7, 0..7] of Integer;
    Grid = Array[0..7] of Array[0..7] of Integer;
    Direction = (Up, Down, Left, Right);

var
   x, y: Integer;

procedure UpdateGrid(var MainGrid: Grid);
var
   i, j: Integer;
begin
     for (i := 0 to (Length(MainGrid) - 1)) do
     begin
          for (j := 0 to (Length(MainGrid[i] - 1)) do
          begin
              MainGrid[i][j] := GetColor(189 + (i * 40), 45 + (j * 40));
          end;
     end;
end;

procedure MovePieceDirection(i: Integer, j: Integer, Dir: Direction);
begin
     case Dir of
     Up: begin HoldMouse(189 + (i * 40), 45 + (j * 40), true);
               wait(10);
               MoveMouseSmooth(189 + (i * 40), 45 + ((j - 1) * 40));
               wait(10);
               ReleaseMouse(189 + (i * 40), 45 + ((j - 1) * 40), true);
               end
     Down: begin HoldMouse(189 + (i * 40), 45 + (j * 40), true);
                 wait(10);
                 MoveMouseSmooth(189 + (i * 40), 45 + ((j + 1) * 40));
                 wait(10);
                 ReleaseMouse(189 + (i * 40), 45 + ((j + 1) * 40), true);
                 end
     Left: begin HoldMouse(189 + (i * 40), 45 + (j * 40), true);
                 wait(10);
                 MoveMouseSmooth(189 + ((i + 1) * 40), 45 + (j * 40));
                 wait(10);
                 ReleaseMouse(189 + ((i + 1) * 40), 45 + (j * 40), true);
                 end
     Right: begin HoldMouse(189 + (i * 40), 45 + (j * 40), true);
                  wait(10);
                  MoveMouseSmooth(189 + ((i - 1) * 40), 45 + (j * 40));
                  wait(10);
                  ReleaseMouse(189 + ((i - 1) * 40), 45 + (j * 40), true);
                  end
end;

procedure MovePiece(MainGrid: Grid);
begin
     for (i := 0 to (Length(MainGrid) - 1)) do
     begin
          for (j := 0 to (Length(MainGrid[i] - 1)) do
          begin
              if ((MainGrid[i][j] = MainGrid[i + 2][j]) AND
                 (MainGrid[i][j] = MainGrid[i + 3][j])) then
              begin
                   MovePieceDirection(i, j, Left);
                   exit;
              end
              else if ((MainGrid[i][j] = MainGrid[i - 2][j]) AND
                 (MainGrid[i][j] = MainGrid[i - 3][j]))
              begin
                   MovePieceDirection(i, j, Right);
                   exit;
              end
              else if ((MainGrid[i][j] = MainGrid[i][j + 2]) AND
                 (MainGrid[i][j] = MainGrid[i][j + 3]))
              begin
                   MovePieceDirection(i, j, Down);
              end
              else if ((MainGrid[i][j] = MainGrid[i][j - 2]) AND
                 (MainGrid[i][j] = MainGrid[i][j - 3]))
              begin
                   MovePieceDirection(i, j, Up);
              end
          end;
     end;
end;

procedure Main();
var MainGrid: Grid;
begin
     repeat
           UpdateGrid(MainGrid);
           MovePiece(MainGrid);
           wait(800);
     until(false);
end;

begin
     Main();
end.

procedure UpdateGrid(var MainGrid: Grid); (the first line from top to bottom where grid is used) is returning the error. :(

Any help with this? It should "know" what a grid is by this point :\
 
Code:
type
    Grid = record
      IntArray : Array[0..7] of Array[0..7] of Integer;
    end;
    Direction = (Up, Down, Left, Right);

Call it like this:

Grid.IntArray

~Sandstorm
 
If I define it like that, can I still call it like... grid[j]? yeah?

So AGrid[j] will be an int?

EDIT:

It'll be Grid.Intarray[j] yeah?
 
Runescape Gamblingrunescape gambling
Back
Top