mat_de_b
10-08-2007, 06:50 PM
This is more of an intermediate tutorial but since i dont think non-members can see them i thought i would post it here... need a fair bit of prior knowledge, including Setting up variables, for to do clauses <- not 100% necessary, findcolorspirals and a general understanding...
1. Background Info
What is an array you ask?
I like to think of it as a way of storing many variables to one name...
How is this useful?
When finding a NPC for instance this will life far easier and more proffesional... all i can say is lucky you!
2. Our first Array
How does one go about making an array?
Like any other variable an array must be called at the begining of a script or procedure like this
var
Color : array [0..4] of Integer;
This allows us to store 5 values to the variable Color. The first number here 0 is the first value that can be stored and the second number here 4 is the last value that can be set
How do we set values in our Array?
Arrays are indexed using a number in square brackets after the array name, like so:
Color[0] = 12345;
This sets the first value in our array to 12345 but the others remain unchanged to change them all one would use:
program New;
var
Color : array [0..4] of Integer;
begin
Color[0] := 12345;
Color[1] := 1234;
Color[2] := 123;
Color[3] := 12;
Color[4] := 1;
end.
3. How does a l33th4ax0r such as yourself use this to find an NPC?
Now that we have set our colors we must look for each one in order to find the NPC, now we could write out a million find colors? but here is the promise posed by an array.
program New;
{.include srl/srl.scar}
var
Color : array [0..4] of Integer;
i,x,y : integer;
Found : boolean;
procedure LoadColors;
begin
Color[0] := 12345;
Color[1] := 1234;
Color[2] := 123;
Color[3] := 12;
Color[4] := 1;
end;
begin
LoadColors;
For i:= 0 to 4 do
begin
if(FindColorSpiral(x,y,Color[i],MSX1,MSY1,MSX2,MSY2))then
begin
Found := True;
Writeln('Found the color you speak of');
Break;
end;
end;
if(Found = False)then
Exit;
end.
For each repetition of this I will be increased until it equals 4 (the last value of our Array) this means that it searches for each color 1 after another, then if it finds the color it will break the loop meaning that you get the correct x and y :D Happy us
4.Taking this that one step further!
Now you say i like what your telling me but surely theres more to it? and there is! here is how to edit your array on run time and allow yourself to get the correct colors!
First we establish our array and look for it with a tolerance doing almost the same as in 3.
program New;
{.include srl/srl.scar}
var
Color : array of Integer;
i,x,y : integer;
Found : boolean;
procedure LoadColors;
begin
SetArrayLength(Color,5);
Color[0] := 12345;
Color[1] := 1234;
Color[2] := 123;
Color[3] := 12;
Color[4] := 1;
end;
begin
LoadColors;
For i:= 0 to 4 do
begin
if(FindColorSpiralTolerance(x,y,Color[i],MSX1,MSY1,MSX2,MSY2,15))then
begin
Found := True;
Writeln('Found the color you speak of');
Break;
end;
end;
if(Found = False)then
Exit;
end.
However this time we want to add the color to our array! we therefor 2must add length to our array and store a color to it, this is how its done!
SetArrayLength(Color,GetArrayLength(Color) +1); // This increases the amount of values Color an handle
Color[GetArrayLength(Color) - 1] := GetColor(x,y); // This makes the largest value of Color equal the colour you just found!
// The -1 is used becuase the starting value of the array is 0 and so all values will be 1 lower than the total length...
And this is how that is used in a script:
program New;
{.include srl/srl.scar}
var
Color : array of Integer;
i,x,y : integer;
Found : boolean;
procedure LoadColors;
begin
SetArrayLength(Color,5);
Color[0] := 12345;
Color[1] := 1234;
Color[2] := 123;
Color[3] := 12;
Color[4] := 1;
end;
begin
LoadColors;
For i:= 0 to (GetArrayLength(Color) - 1) do
begin
if(FindColorSpiralTolerance(x,y,Color[i],MSX1,MSY1,MSX2,MSY2,15))then
begin
SetArrayLength(Color,GetArrayLength(Color) +1); // This increases the amount of values Color an handle
Color[GetArrayLength(Color) - 1] := GetColor(x,y); // This makes the largest value of Color equal the colour you just found!
Found := True;
Writeln('Found the color you speak of');
Break;
end;
end;
if(Found = False)then
Exit;
end.
This code will add all new found colors to the Array and will then look for all of the colors...
Hope you enjoyed this tutorial and i hope its beneficial, if i've left you a bit :confused: then feel free to pm/comment here and ill help you out...
1. Background Info
What is an array you ask?
I like to think of it as a way of storing many variables to one name...
How is this useful?
When finding a NPC for instance this will life far easier and more proffesional... all i can say is lucky you!
2. Our first Array
How does one go about making an array?
Like any other variable an array must be called at the begining of a script or procedure like this
var
Color : array [0..4] of Integer;
This allows us to store 5 values to the variable Color. The first number here 0 is the first value that can be stored and the second number here 4 is the last value that can be set
How do we set values in our Array?
Arrays are indexed using a number in square brackets after the array name, like so:
Color[0] = 12345;
This sets the first value in our array to 12345 but the others remain unchanged to change them all one would use:
program New;
var
Color : array [0..4] of Integer;
begin
Color[0] := 12345;
Color[1] := 1234;
Color[2] := 123;
Color[3] := 12;
Color[4] := 1;
end.
3. How does a l33th4ax0r such as yourself use this to find an NPC?
Now that we have set our colors we must look for each one in order to find the NPC, now we could write out a million find colors? but here is the promise posed by an array.
program New;
{.include srl/srl.scar}
var
Color : array [0..4] of Integer;
i,x,y : integer;
Found : boolean;
procedure LoadColors;
begin
Color[0] := 12345;
Color[1] := 1234;
Color[2] := 123;
Color[3] := 12;
Color[4] := 1;
end;
begin
LoadColors;
For i:= 0 to 4 do
begin
if(FindColorSpiral(x,y,Color[i],MSX1,MSY1,MSX2,MSY2))then
begin
Found := True;
Writeln('Found the color you speak of');
Break;
end;
end;
if(Found = False)then
Exit;
end.
For each repetition of this I will be increased until it equals 4 (the last value of our Array) this means that it searches for each color 1 after another, then if it finds the color it will break the loop meaning that you get the correct x and y :D Happy us
4.Taking this that one step further!
Now you say i like what your telling me but surely theres more to it? and there is! here is how to edit your array on run time and allow yourself to get the correct colors!
First we establish our array and look for it with a tolerance doing almost the same as in 3.
program New;
{.include srl/srl.scar}
var
Color : array of Integer;
i,x,y : integer;
Found : boolean;
procedure LoadColors;
begin
SetArrayLength(Color,5);
Color[0] := 12345;
Color[1] := 1234;
Color[2] := 123;
Color[3] := 12;
Color[4] := 1;
end;
begin
LoadColors;
For i:= 0 to 4 do
begin
if(FindColorSpiralTolerance(x,y,Color[i],MSX1,MSY1,MSX2,MSY2,15))then
begin
Found := True;
Writeln('Found the color you speak of');
Break;
end;
end;
if(Found = False)then
Exit;
end.
However this time we want to add the color to our array! we therefor 2must add length to our array and store a color to it, this is how its done!
SetArrayLength(Color,GetArrayLength(Color) +1); // This increases the amount of values Color an handle
Color[GetArrayLength(Color) - 1] := GetColor(x,y); // This makes the largest value of Color equal the colour you just found!
// The -1 is used becuase the starting value of the array is 0 and so all values will be 1 lower than the total length...
And this is how that is used in a script:
program New;
{.include srl/srl.scar}
var
Color : array of Integer;
i,x,y : integer;
Found : boolean;
procedure LoadColors;
begin
SetArrayLength(Color,5);
Color[0] := 12345;
Color[1] := 1234;
Color[2] := 123;
Color[3] := 12;
Color[4] := 1;
end;
begin
LoadColors;
For i:= 0 to (GetArrayLength(Color) - 1) do
begin
if(FindColorSpiralTolerance(x,y,Color[i],MSX1,MSY1,MSX2,MSY2,15))then
begin
SetArrayLength(Color,GetArrayLength(Color) +1); // This increases the amount of values Color an handle
Color[GetArrayLength(Color) - 1] := GetColor(x,y); // This makes the largest value of Color equal the colour you just found!
Found := True;
Writeln('Found the color you speak of');
Break;
end;
end;
if(Found = False)then
Exit;
end.
This code will add all new found colors to the Array and will then look for all of the colors...
Hope you enjoyed this tutorial and i hope its beneficial, if i've left you a bit :confused: then feel free to pm/comment here and ill help you out...