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;
YewColor : Array [0..5] of Integer;
If (not (Loggedin)) then
For i:= 0 to 5 do
If FindObjCustom(x,y,['ew'],[YewColor[i]],5) then
If IsUpText('ew') then
Firstly there are two things you should know, There are two different ways of declaring them. Declaring meaning the line under
<-- Our variables. They must be declared at the beginning of the procedure (Local Declaration) or the script (Global declaration)SCAR Code:var
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 )
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:
is the color of the yew, pretty self explanatory.SCAR Code:YewColor
SCAR Code:YewColor := ......
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
How to Use 'em In Your Script?
For how many numbers you entered in the
bit you have to use the lineSCAR Code:YewColor : Array [ --> 0..5 <-- ] of Integer;
see where we got that from?SCAR Code:for 0 to 5 do
When we declared the array we made out how many colours we could store (6).
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
You can use an array instead
" Arrays, great for saving time and effort
Hopefully you understood that short tut.
Might add another section soon.
If you liked this TUT don't froget I always like a bit of reppage <--!!!