SRL Archive - OSR Advanced Scripting Tutorials

Array in an array...


Lorax

2006-12-18 04:31:01

Ever wanted to make those neat arrays that no one, but yourself understand?
Well I like to make them often and very advanced..
Here I will suggest that you have read Kanes tutorial on arrays before starting, because I will not teach you arrays from the start

[PHP]
var
myArray: Array of Array of Array of Integer;
[/PHP]

That's the kind of arrays I will teach you to use today..

You might ask yourself, what could I use those arrays for? They just seem to be a lot of work..

I found use of them several times, let me give you my latest example:

[PHP]
var
aPoints: Array[0..2]of TPointArray;

begin
for aCount := 0 to 2 do
begin
FindColorsTolerance(aPoints[aCount], color,1, 1, 515, 336, 10);
Wait(50);
end;
for aCount := 0 to 2 do
for bCount := 0 to GetArrayLength(aPoint[aCount]) - 1 do
[/PHP]

This script will find all the colors 3 times, and then loop through them all, perhaps you could make a gas solver out of this..

I know that StarBlaster also uses multidimensional arrays in his Essense miner…

Simple as it sounds, when you want to make a multidimensional you just define an array of an array..

and when you want to get info from it you make two boxes:

[PHP]
var
myArray: Array of Array of String;
myString: String;

begin
myString := 'IOWN';
SetArrayLength(myArray, 1);
for aCount := 0 to Length(myString) - 1 do
begin
SetArrayLength(myArray[0], aCount + 1);
Array[0][aCount] := myString.aCount;
end;

and so on and so on..
[/PHP]

Can someone say autoresponder? :)

I see the use of multi dimensional arrays everywhere, but don't overdo it… you need to understand it yourself

I hope you found it usefull, if you didn't then you aren't ready to learn the secrets of multi dimensional arrays..

Boreas

2006-12-18 08:43:40

Nice. We need more tuts like this, the weird crap that no one ever talks about.

Pyro

2006-12-18 15:34:40

Ooooo thanks. I always had a problem with setting multidimension arrays. now i see. So you call set the first bit then when you set the second you call it as (array[whatever],length) yip yip gotcha.

Thanks heaps.

ShawnjohnSJ

2007-05-04 22:32:27

Aha yes just what I was looking for. Thanks.

I did the same thing except in C++ format :P

Wizzup?

2007-05-05 04:29:20

I've made an autoresponder with 2 dimensional arrays a long time ago.. but I got lazy on the part filling every word in and thinking of sentences..

Starblaster100

2007-05-05 06:52:55

nice tut.

Directly from my ess miner:
[php]
MoveCount: Array[1..6] of Array[1..12] of Integer;
[/php]

rkroxpunk

2007-05-09 08:28:51

0.o this was in the beginners section? now I feel really nubular :s

TehElite

2008-07-23 18:32:45

From: rkroxpunk
0.o this was in the beginners section? now I feel really nubular :s


Agreed, I didn't understand much in this tutorial.

Scaper

2008-07-23 22:34:24

try reading more tuts and getting more knowledge befor trying tu sus what these are from

Harry

2008-07-23 23:16:12

From: TehElite
Agreed, I didn't understand much in this tutorial.


EPIC FAIL.
12-18-2006, 04:31 AM


Good tut anyways Lorax.

EvilChicken!

2008-07-24 05:20:13

From: Hy71194
EPIC FAIL.
12-18-2006, 04:31 AM


Good tut anyways Lorax.


It is a good tutorial, it is supposed to teach people stuff, and I don't think the author wrote this tutorial for the purpose of it being hid away and ignored. I see absolutely nothing wrong with "gravedigging tutorials", as long as they are useful to the community. If old, useful tutorials are gravegug, "newer" members of this community might read them because they found then unintentionally.

To comment the tutorial: An easier way to declare 2/3D arrays would be T3D(int/point/ect)Array. :) Otherwise nice tutorial, should maybe be in the intermediate section? Newer scripters may be intimidated/scared away by this.. :rolleyes:

gizmix

2008-08-28 16:29:03

O, i thought it was harder =/.

Lucky i found this straight away, Was just thinking about it.

elvew

2008-08-29 00:20:02

thx for tut

Macro_FTW

2009-06-25 09:22:33

Helpful and easy. Nice tutorial.

Rep++.

cycrosism

2009-08-02 13:53:22

nice 10 month gravedig

Sabzi

2009-08-02 13:56:38

AFAIK tutorials can't be gravedigged. It's even worth to bump some old, forgotten but good tutorials. And this one doesn't seem outdated but helpfull.

weequ

2010-01-16 15:23:08

Thanks this will help me alot :)

Edit: Damn I don't understand…
I have:

var
arr123: Array of TStringArray;
begin
arr123 := [[''],['']];
end;
How should it be like?


Edit2: Figured out that I can do it this way:

var
arr123: Array[0..2]of TStringArray;
begin
arr123[0] := [''];
arr123[1] := [''];
end;
But is there a way to do that in 1 line?

Gu3st...

2010-01-16 15:45:13

From: antti mies
Thanks this will help me alot :)

Edit: Damn I don't understand…
I have:

var
arr123: Array of TStringArray;
begin
arr123 := [[''],['']];
end;
How should it be like?

var
sArr array of array of string; // same as array of TStringArray; or T2DStringArray;
H, I : Integer;

begin
SetArrayLength(sArr, 2);
H := High(sArr); // We already know the high is 1 but this is good for learning
for I := 0 to H do
SetArrayLength(sArr[I], 2);
sArr[0][0] := 'Hello';
sArr[0][1] := 'Hi';
sArr[1][0] := 'Bye';
sArr[1][1] := 'cya';
end.

Remember arrays starts counting at 0, so an array with the length of 3 would be 0-2

weequ

2010-01-16 15:47:48

Thanks Zyt3x but is there a way to do these:

sArr[0][0] := 'Hello';
sArr[0][1] := 'Hi';
sArr[1][0] := 'Bye';
sArr[1][1] := 'cya';
in 1 line?

Naum

2010-01-16 16:06:04

From: antti mies
Thanks Zyt3x but is there a way to do these:

sArr[0][0] := 'Hello';
sArr[0][1] := 'Hi';
sArr[1][0] := 'Bye';
sArr[1][1] := 'cya';
in 1 line?


 SArr := [TStringArray(['Hello', 'Hi']), TStringArray(['Bye', 'Cya'])];
;)

weequ

2010-01-16 16:10:38

Tyvm!