Results 1 to 12 of 12

Thread: Multi-Dimensional Arrays with Simba?

  1. #1
    Join Date
    Mar 2013
    Location
    Narnia
    Posts
    182
    Mentioned
    1 Post(s)
    Quoted
    62 Post(s)

    Default Multi-Dimensional Arrays with Simba?

    Hey, I'm not sure if this is the right place for this... If not, please tell me where it should be.


    Am I doing something wrong?
    Does simba not support multi-dimensional arrays?
    if so then why the hell not...

    I've been trying to get multi-dimensional arrays to work in a script, however for some reason simba doesn't want to cooperate. Here's what I've tried:

    Simba Code:
    var
      a: array [0..3,0..3] of integer;
    [Error] Closing square bracket (']') expected at line 907
    Compiling failed.

    Simba Code:
    var
      a: array [0..3,0..3] of TintegerArray;
    [Error] Closing square bracket (']') expected at line 907
    Compiling failed.

    Simba Code:
    var
      a: array [0..3][0..3] of integer;
    [Error] 'OF' expected at line 907
    Compiling failed.

    Simba Code:
    var
      a: array [0..3],[0..3] of integer;
    [Error] 'OF' expected at line 907
    Compiling failed.

    Simba Code:
    var
      a: array [0..3],[0..3] of TIntegerArray;
    [Error] 'OF' expected at line 907
    Compiling failed.

    Simba Code:
    var
      a: array [3,3] of integer;
    [Error] period ('.') expected at line 907
    Compiling failed.

    Simba Code:
    var
      a: array [3,3] of TIntegerArray;
    [Error] period ('.') expected at line 907
    Compiling failed.

    Simba Code:
    var
      a: array [3.3] of TIntegerArray;
    [Error] Type mismatch at line 907
    Compiling failed.

    Simba Code:
    var
      a: array [3.3] of Integer;
    [Error] Type mismatch at line 907
    Compiling failed.

  2. #2
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default

    I believe a multidimensional array should be more like this:
    Simba Code:
    var
      a: array [0..3] of array[0..3] of Integer;

    That's done off memory and not anything exact (not by a simba instance atm either). But I think it was either that or:
    Simba Code:
    var
      a: array [0..3] of (array[0..3] of Integer);

    Edit: you can however, definitely do this:
    Simba Code:
    var
      a: array [0..3] of TIntegerArray;

  3. #3
    Join Date
    Mar 2013
    Location
    Narnia
    Posts
    182
    Mentioned
    1 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by Kevin View Post
    I believe a multidimensional array should be more like this:
    Simba Code:
    var
      a: array [0..3] of array[0..3] of Integer;
    i love youuuuuuuuu

  4. #4
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

  5. #5
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Could also be done like:
    Simba Code:
    var
     myarr:T2DIntegerArray
    (Works with TPointArray, haven't tested with Integers?)

  6. #6
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Excuse me for posting off topic but what are 2d arrays used for besides atpa stuff?

  7. #7
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Quote Originally Posted by Officer Barbrady View Post
    Excuse me for posting off topic but what are 2d arrays used for besides atpa stuff?
    http://processing.org/learning/2darray/

  8. #8
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default

    Quote Originally Posted by Officer Barbrady View Post
    Excuse me for posting off topic but what are 2d arrays used for besides atpa stuff?
    At the moment I can't come up with a srl example, however let's look at a gaming example.

    Let's say I wanna store every monster in a dungeon in one variable called monsters. I COULD do it with a one dimensional array, but let's complicate it a little. Let's say some of these monsters are leaders of their repesentative group of monsters by them. So, instead of updating all monsters, I want to update all Leaders - and those leaders can tell their monsters what to do. In a simple loop I could do then udpate every leader, and every leader (position in the first dimension) would update each of his monsters underneath him (position in the second dimension).

  9. #9
    Join Date
    Jun 2012
    Location
    Howell, Michigan
    Posts
    1,585
    Mentioned
    34 Post(s)
    Quoted
    553 Post(s)

    Default

    Quote Originally Posted by Kevin View Post
    At the moment I can't come up with a srl example, however let's look at a gaming example.

    Let's say I wanna store every monster in a dungeon in one variable called monsters. I COULD do it with a one dimensional array, but let's complicate it a little. Let's say some of these monsters are leaders of their repesentative group of monsters by them. So, instead of updating all monsters, I want to update all Leaders - and those leaders can tell their monsters what to do. In a simple loop I could do then udpate every leader, and every leader (position in the first dimension) would update each of his monsters underneath him (position in the second dimension).

    It would also be useful for letting as well, like make a spread of red dots total, then make a spread of red dots near your NPC and have it update to that?

  10. #10
    Join Date
    Mar 2013
    Location
    Narnia
    Posts
    182
    Mentioned
    1 Post(s)
    Quoted
    62 Post(s)

    Default

    One more question..

    Simba Code:
    var
      Char:Array [1..7] of Array [0..2] of String;
    begin
      char[1] := (['char0','char1','char2']);

    why doesn't this work..? it doesn't seem to want to assign char[1] to the array listed.
    And I don't think doing this is the right way:
    Simba Code:
    begin
      char[1][0] := 'char0';
      char[1][1] := 'char1';
      Char[1][2] := 'char2';
    what am i doing wrong..?

  11. #11
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Quote Originally Posted by aaron126 View Post
    One more question..

    Simba Code:
    var
      Char:Array [1..7] of Array [0..2] of String;
    begin
      char[1] := (['char0','char1','char2']);

    why doesn't this work..? it doesn't seem to want to assign char[1] to the array listed.
    And I don't think doing this is the right way:
    Simba Code:
    begin
      char[1][0] := 'char0';
      char[1][1] := 'char1';
      Char[1][2] := 'char2';
    what am i doing wrong..?
    I highly recommend you don't name the variable as "Char" or "char", because Char is a variable type by Delphi/Pascal.

    Anyways, let's see now...

    Code:
    var
      chars: array[1..7] of array[0..2] of string;
    
    begin
      chars[1] := ['char0', 'char1', 'char2'];
    end.
    The problem is, that you are treating static array as dynamic array (chars[1] := ['char0', 'char1', 'char2']).

    So you have pretty much 2 options here.

    A. Changing latter array to dynamic:
    Code:
    var
      chars: array[1..7] of array of string;
    
    begin
      chars[1] := ['char0', 'char1', 'char2'];
    end.
    ..or...

    B. Treating static array as static array:
    Code:
    var
      chars: array[1..7] of array[0..2] of string;
    
    begin
      chars[1][0] := 'char0';
      chars[1][1] := 'char1'
      chars[1][2] := 'char2';
    end.
    -Jani

  12. #12
    Join Date
    Mar 2013
    Location
    Narnia
    Posts
    182
    Mentioned
    1 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by Janilabo View Post
    I highly recommend you don't name the variable as "Char" or "char", because Char is a variable type by Delphi/Pascal.

    Anyways, let's see now...

    Code:
    var
      chars: array[1..7] of array[0..2] of string;
    
    begin
      chars[1] := ['char0', 'char1', 'char2'];
    end.
    The problem is, that you are treating static array as dynamic array (chars[1] := ['char0', 'char1', 'char2']).

    So you have pretty much 2 options here.

    A. Changing latter array to dynamic:
    Code:
    var
      chars: array[1..7] of array of string;
    
    begin
      chars[1] := ['char0', 'char1', 'char2'];
    end.
    ..or...

    B. Treating static array as static array:
    Code:
    var
      chars: array[1..7] of array[0..2] of string;
    
    begin
      chars[1][0] := 'char0';
      chars[1][1] := 'char1'
      chars[1][2] := 'char2';
    end.
    -Jani
    aaah I see. thanks. ^.^
    and yeah i know, I was just slopping an example together. I didn't name it Char in the actual usage. :P

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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