# Thread: Static Arrays!!!!

1. ## Static Arrays!!!!

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:

SCAR Code:
`Procedure CutTree;VarYewColor : 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
SCAR Code:
`var`
<-- Our variables. They must be declared at the beginning of the procedure (Local Declaration) or the script (Global declaration)

One way:
SCAR Code:
`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:
SCAR Code:
`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:

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

SCAR Code:
`YewColor`
is the color of the yew, pretty self explanatory.

SCAR Code:
`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
SCAR Code:
`YewColor : Array [ --> 0..5 <-- ] of Integer;`
bit you have to use the line

SCAR Code:
`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:

SCAR Code:
`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:

SCAR Code:
`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:

SCAR Code:
`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 <--!!!

2. Community Member
Join Date
Jul 2007
Posts
1,440
Mentioned
0 Post(s)
Quoted
0 Post(s)
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.

3. 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.

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

5. Originally Posted by 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...

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

7. Senior SRL Member
Join Date
Jun 2006
Posts
3,864
Mentioned
2 Post(s)
Quoted
0 Post(s)
Originally Posted by NaumanAkhlaQ
One way:
SCAR Code:
`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

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

That green is painful, but thanks for the tut

9. 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.

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

Nava2

11. SRL Junior Member
Join Date
Apr 2008
Posts
67
Mentioned
0 Post(s)
Quoted
0 Post(s)
really nice tut.
Now i know more about arrays.
Maybe i should use them too. oO

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

SCAR Code:
`If FindColor(blah) orFindColor(blah)`

13. First Time Poster
Join Date
Sep 2008
Posts
1
Mentioned
0 Post(s)
Quoted
0 Post(s)
yoz

14. 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:

SCAR Code:
`const MyArray := ('Hello',                  'Goodbye.')`

is.

15. Senior SRL Member
Join Date
Jun 2006
Posts
3,864
Mentioned
2 Post(s)
Quoted
0 Post(s)
R0b0t, you fail at delphi
SCAR Code:
`const MyArray = ['Hello', 'Goodbye'];`

16. 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++

17. SRL Junior Member
Join Date
Jan 2009
Location
Belgium
Posts
124
Mentioned
0 Post(s)
Quoted
0 Post(s)
Very nice tutorial, i learned how to use the arrays abit better now, thank you

rep+

18. 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

19. Originally Posted by 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

20. Originally Posted by 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

21. Registered User
Join Date
Dec 2006
Location
Georgia
Posts
84
Mentioned
0 Post(s)
Quoted
0 Post(s)
Thank you!!!!!

22. 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