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;
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
<-- Our variables. They must be declared at the beginning of the procedure (Local Declaration) or the script (Global declaration)SCAR Code:var
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;
is the color of the yew, pretty self explanatory.SCAR Code:YewColor
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
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).
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 <--!!!










) 

Reply With Quote









) 





