SRL Archive - Research & Development Lounge

Multi-Dimensional Arrays with Simba?


aaron126

2013-05-21 15:19:59

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:


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


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


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


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


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


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


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


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


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

Kevin

2013-05-21 15:22:28

I believe a multidimensional array should be more like this:
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:
var
a: array [0..3] of (array[0..3] of Integer);

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

aaron126

2013-05-21 15:28:16

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



i love youuuuuuuuu

Kevin

2013-05-21 15:44:19

From: aaron126
i love youuuuuuuuu


:D

NKN

2013-05-21 16:53:11

Could also be done like:

var
myarr:T2DIntegerArray
(Works with TPointArray, haven't tested with Integers?)

rj

2013-05-21 16:55:15

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

NKN

2013-05-21 17:13:24

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


http://processing.org/learning/2darray/

Kevin

2013-05-21 17:21:17

From: Officer Barbrady
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).

King

2013-05-21 18:20:40

From: Kevin
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?

aaron126

2013-05-22 02:59:27

One more question..


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:

begin
char[1][0] := 'char0';
char[1][1] := 'char1';
Char[1][2] := 'char2';
what am i doing wrong..?

Janilabo

2013-05-22 07:50:55

From: aaron126
One more question..


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:

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…

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:
var
chars: array[1..7] of array of string;

begin
chars[1] := ['char0', 'char1', 'char2'];
end.

..or…

B. Treating static array as static array:
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

aaron126

2013-05-22 10:36:44

From: Janilabo
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…

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:
var
chars: array[1..7] of array of string;

begin
chars[1] := ['char0', 'char1', 'char2'];
end.

..or…

B. Treating static array as static array:
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