2D array?

Discussion in 'Scar/Simba Help' started by v4mp1r3-2, Sep 12, 2009.

2D array?
  1. Unread #1 - Sep 12, 2009 at 7:57 AM
  2. v4mp1r3-2
    Joined:
    Jan 10, 2006
    Posts:
    5
    Referrals:
    0
    Sythe Gold:
    0

    v4mp1r3-2 Newcomer

    2D array?

    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?
     
  3. Unread #2 - Sep 12, 2009 at 12:46 PM
  4. Hey321
    Joined:
    Jul 30, 2007
    Posts:
    503
    Referrals:
    0
    Sythe Gold:
    0

    Hey321 Forum Addict

    2D array?

    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
     
  5. Unread #3 - Sep 12, 2009 at 8:06 PM
  6. v4mp1r3-2
    Joined:
    Jan 10, 2006
    Posts:
    5
    Referrals:
    0
    Sythe Gold:
    0

    v4mp1r3-2 Newcomer

    2D array?

    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 :\
     
  7. Unread #4 - Sep 12, 2009 at 10:20 PM
  8. Hey321
    Joined:
    Jul 30, 2007
    Posts:
    503
    Referrals:
    0
    Sythe Gold:
    0

    Hey321 Forum Addict

    2D array?

    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
     
  9. Unread #5 - Sep 12, 2009 at 11:00 PM
  10. v4mp1r3-2
    Joined:
    Jan 10, 2006
    Posts:
    5
    Referrals:
    0
    Sythe Gold:
    0

    v4mp1r3-2 Newcomer

    2D array?

    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?
     
  11. Unread #6 - Sep 13, 2009 at 2:04 AM
  12. Hey321
    Joined:
    Jul 30, 2007
    Posts:
    503
    Referrals:
    0
    Sythe Gold:
    0

    Hey321 Forum Addict

    2D array?

    Your third idea is right.

    ~Sandstorm
     
< Srl? | Learn to script now ! Online Tutorial ! >

Users viewing this thread
1 guest


 
 
Adblock breaks this site