SRL Archive - OSR Beginner Scripting Tutorials

Static Arrays!!!!


Naum

2008-04-03 12:52:02

All About Static Arrays!!!




Welcome to NaumanAkhlaQ's tutorial for using and implementing arrays in your script.


What are arrays used for?


Arrays take two forms -

–> One of them are static arrays which run within the script, basically they stay the same.

–> The second are ones which take info from the client at specific points, a prime example being DDTM's.


In this tutorial we will cover Statics Arrays


So How'd You Declare Them?


Here is an example:



Procedure CutTree;
Var
YewColor : Array [0..5] of Integer;
i :Integer;
Begin
YewColor[0]:=2182984;
YewColor[1]:=1855560;
YewColor[2]:=4426622;
YewColor[3]:=1914933;
YewColor[4]:=3239519;
YewColor[5]:=3116158;
Begin
If (not (Loggedin)) then
Exit;
else
For i:= 0 to 5 do
If FindObjCustom(x,y,['ew'],[YewColor[i]],5) then
Begin
If IsUpText('ew') then
Begin
CutDown;
end;
end;
end;


Firstly there are two things you should know, There are two different ways of declaring them. Declaring meaning the line under
 var  
<– Our variables. They must be declared at the beginning of the procedure (Local Declaration) or the script (Global declaration)

One way:

SetArrayLength(YewColor, 5)

That says that there are 5 different arrays which are in the Integer , so in this case 4 different colors (0..4 :))

Second Way:

YewColor : Array [0..5] of Integer;

^ I prefer this way as I am a ' . ' maniac! ^



So How'd You Set Them up?



Refering to our first example:


YewColor[0]:=2182984;
YewColor[1]:=1855560;
YewColor[2]:=4426622;
YewColor[3]:=1914933;
YewColor[4]:=3239519;
YewColor[5]:=3116158;

YewColor
is the color of the yew, pretty self explanatory.


YewColor[0] := ......

When you use them you put the number in this case [0..5] on the end in square brackets because if you don’t you get a 'Duplicate
Identifier' error!


How to Use 'em In Your Script?


For how many numbers you entered in the

YewColor : Array [ --> 0..5 <-- ] of Integer;

bit you have to use the line

 for 0 to 5 do 

see where we got that from?
When we declared the array we made out how many colours we could store (6).

Now what:

 for i:=0 to 5 do 


does is it looks at all the colors and incorporates it in the next line so in the next line we have to have:

 For i:= 0 to 5 do
If FindObj(x,y,'ree',YewColor[i],6) then....

the integer ' i ' searches all the arrays for 0 to 5 so instead of using a
Function like this:


If FindObj(x,y,'ree',4354,5) or
FindObj(x,t,'Tre',976897,5) or
{so on}

You can use an array instead :)

Confucious say:

" Arrays, great for saving time and effort :)


Hopefully you understood that short tut.
Might add another section soon.

Peace Out :)



If you liked this TUT don't froget I always like a bit of reppage <–!!!

Negaal

2008-04-03 14:06:54

Hmm, maybe make font more readable? Really it dont have to big and colorful, it makes it only harder to read…

else, very useful…nice.

n3ss3s

2008-04-03 14:19:40

Ehm… Nauman… The purpose of something doesn't change what it is, an array of TDTMPointDef, aka DDTM, is just like any other array with more variables.

DDTMs are just as dynamic as TPointArrays or any other array.

senrath

2008-04-03 14:22:14

Nice tut, though these aren't truly static arrays, since they can be changed from within the running script.

Naum

2008-04-04 05:55:57

Oh didn't know that.
sorry.

Freddy1990

2008-04-04 06:29:43

From: senrath
Nice tut, though these aren't truly static arrays, since they can be changed from within the running script.


They are static arrays, just not constant static arrays…
Btw, decent tutorial, but the font hurts my eyes…

senrath

2008-04-04 06:42:01

My bad, I keep mixing those two up. Yeah, I guess they are static since they don't ever change in length. Whoops :P

bullzeye95

2008-04-04 07:43:19

From: NaumanAkhlaQ
One way:

SetArrayLength(YewColor, 5)

That says that there are 5 different arrays which are in the Integer , so in this case 6 different colors (Including [0] remember ;) )


Incorrect, the array would only have 0..4. Other than that, the tutorial's good :)

Naum

2008-04-04 09:57:48

Ahh ok ill correct that :)

Lee Lok Hin

2008-04-04 10:05:06

Great! Now I can find aggie without tones of ORs.

That green is painful, but thanks for the tut

Naum

2008-04-13 07:13:29

No problem glad i could help :)

Dont froget to rep me ;)

EDIT: Changed the font and the colour.
Thx freddy didn't see your post. ;)

Nava2

2008-04-13 14:30:17

Repped!!!! Thanks, I think this should solve my fishing problem. I just need to test it now.

Nava2

Naum

2008-04-13 14:31:34

Ok no problem :).

Iceevil

2008-04-30 08:41:21

really nice tut.
Now i know more about arrays.
Maybe i should use them too. oO

Naum

2008-04-30 11:40:04

Yeah sure go for it, There the same as using:

 If FindColor(blah) or
FindColor(blah)

;)

ByINSOMaNIAC

2008-10-02 17:07:36

yoz

R0b0t1

2008-10-02 17:34:56

They aren't static/constant arrays you give examples of (even if you argue that by 'static', you mean a fixed length, this thread is a repeat). This:


const MyArray := ('Hello',
'Goodbye.')

is.

bullzeye95

2008-10-02 18:54:28

R0b0t, you fail at delphi :p
const MyArray = ['Hello', 'Goodbye'];

Bionicle

2009-09-20 21:16:39

great tut, but it gave me a headache. not the content, just the font/color lol.
make font a bit smaller and black please :)

rep++

Yush Dragon

2011-01-11 12:45:07

Very nice tutorial, i learned how to use the arrays abit better now, thank you :D

rep+

Troll

2011-01-11 13:54:30

Nice tut :) did not know you could be For To Do on arrays i just used them to do it like a repeat 10 times, so its great thanks

Naum

2011-01-11 14:24:24

From: Troll Man
Nice tut :) did not know you could be For To Do on arrays i just used them to do it like a repeat 10 times, so its great thanks


I made this about 3 years ago.. lol

BraK

2011-01-19 20:22:30

From: Naum
I made this about 3 years ago.. lol


If it still applies it always good to have around I mean look at your Sig. Most of those are still good and I recommend people to them all the Time.

~BraK

imaloser

2012-01-08 05:38:40

Thank you!!!!!

putonajonny

2012-01-10 13:40:06

there are 5 different arrays which are in the Integer


Shouldn't that be:
there are 5 different integers which are in the array

Good tut tho :)

Joe

2012-03-29 19:51:24

Would this be the same on simba as in scar?

Master BAW

2012-06-17 15:49:37

nice :) helped me a little!