JAD
2007-06-26 21:45:56
[Tutorial]
Well, TPoint/TPointArray isn't super complicated, but for the most part only advanced/pretty advanced scripters use it, so I think it's a tutorial for the advanced :)
What you should know before reading this tutorial is:
Of course the grasp of all beginner concepts like variables…etc.
An understanding of how array's work.
for to do loops.
Anyways, let's begin.
TPoint
Well, TPoint is almost exactly like any other old variable, but can have 2 variables within the variable. Just take a look at this example:
See? So pretty much, TPoint is just a variable that you can have 2 variables inside of it, x and y.
So you may be asking, why the heck would I use this? I could just use normal variables couldn't I? Well.. Take a look at this function in SRL:
Now, you may be asking, "Well why couldn't they just use a regular variable there too??". Well, think about it. If they made it
function ItemCoords(I: Integer): Integer;
That wouldn't work for this function. It wouldn't work because you can only save 1 number to the result of an integer function, but there are 2 variables that need to be saved, x and y. So you have to save both of them to the result of the function, and the only way to do that is by using TPoint.
So this is how you could use those variables from the TPoint in that function then:
See how we did that? when we do J := ItemCoords(1), it adds the .x and .y to the TPoint J because those are the results. And then you can make Ax and Ay = J.x and J.y like so.
Hope I explained that well! Moving on to TPointArray.
TPointArray
Well, TPointArray, hence the name, is just an array and TPoint combined :)
So I'm going to show you an example of it, and then explain it below if you didn't get it just from looking through the code:
OK, see that now? Pretty much, an array (with numbers) is Whatever[1] and Whatever[2]….etc. and a TPoint is Whatever.x, Whatever.y. So we are making 2 variables in a number of the array.
So we make OurVar 1-28 = there ItemCoords by number. So it saves it as OurVar[1].x and OurVar[1].y and OurVar[2].x and OurVar[2].y…….etc.
Then we go through and we click the mouse at each inventory slot :)
Well, that's the end of the tutorial. I hope all that clicked and I explained it well and you are on your way to using TPoint/TPointArray in your scripts :)
~JAD
[/Tutorial]
Well, TPoint/TPointArray isn't super complicated, but for the most part only advanced/pretty advanced scripters use it, so I think it's a tutorial for the advanced :)
What you should know before reading this tutorial is:
Of course the grasp of all beginner concepts like variables…etc.
An understanding of how array's work.
for to do loops.
Anyways, let's begin.
TPoint
Well, TPoint is almost exactly like any other old variable, but can have 2 variables within the variable. Just take a look at this example:
procedure Whatever;
var Blah, J: TPoint;
begin
Blah.x := MSX1;
Blah.y := MSY1;
if(FindColor(J.x, J.y,1231251, Blah.x, Blah.y, MSX2, MSY2))then
Mouse(J.x,J.y,1,1,true);
end;
See? So pretty much, TPoint is just a variable that you can have 2 variables inside of it, x and y.
So you may be asking, why the heck would I use this? I could just use normal variables couldn't I? Well.. Take a look at this function in SRL:
{*******************************************************************************
function ItemCoords(i: Integer): TPoint;
By: RsN
Description: Returns X and Y of Specified Inventory Spot
*******************************************************************************}
function ItemCoords(i: Integer): TPoint;
var
row, col: Integer;
begin
row := i div 4;
col := i - (row * 4) - 1;
if (col < 0) then
begin
col := 3;
row := row - 1;
end;
Result.x := 536 + ((col + 1) * 42) + Random(7);
Result.y := 184 + ((row + 1) * 36) + Random(7);
end;
Now, you may be asking, "Well why couldn't they just use a regular variable there too??". Well, think about it. If they made it
function ItemCoords(I: Integer): Integer;
That wouldn't work for this function. It wouldn't work because you can only save 1 number to the result of an integer function, but there are 2 variables that need to be saved, x and y. So you have to save both of them to the result of the function, and the only way to do that is by using TPoint.
So this is how you could use those variables from the TPoint in that function then:
procedure Whatever;
var J: TPoint;
Ax,Ay: Integer;
begin
J := ItemCoords(1);
Ax := J.x
Ay := J.y
Mouse(Ax,Ay,1,1,true);
end;
See how we did that? when we do J := ItemCoords(1), it adds the .x and .y to the TPoint J because those are the results. And then you can make Ax and Ay = J.x and J.y like so.
Hope I explained that well! Moving on to TPointArray.
TPointArray
Well, TPointArray, hence the name, is just an array and TPoint combined :)
So I'm going to show you an example of it, and then explain it below if you didn't get it just from looking through the code:
procedure Whatever;
var
OurVar: TPointArray;
i: integer;
begin
for i := 1 to 28 do
begin
OurVar[i]:= ItemCoords(i); //Makes all of OurVar's = there ItemCoords number
Mouse(OurVar[i].x, OurVar[i].y,1,1,true);
end;
end;
OK, see that now? Pretty much, an array (with numbers) is Whatever[1] and Whatever[2]….etc. and a TPoint is Whatever.x, Whatever.y. So we are making 2 variables in a number of the array.
So we make OurVar 1-28 = there ItemCoords by number. So it saves it as OurVar[1].x and OurVar[1].y and OurVar[2].x and OurVar[2].y…….etc.
Then we go through and we click the mouse at each inventory slot :)
Well, that's the end of the tutorial. I hope all that clicked and I explained it well and you are on your way to using TPoint/TPointArray in your scripts :)
~JAD
[/Tutorial]