SRL Archive - Help and Support

Need Help Again


[S]paz

2008-02-23 07:57:28

Ok, im trying to learn Tpa's, more specifically Tbox's
I read Infantry's tut on it and came up with this

{.Include SRL/SRL.scar}
var
x, y : Integer;
MyTBox : TBox;

function FindColorInBox(x,y,color : integer) : boolean;
begin
MyTBox.x1 := x - 30;
MyTBox.y1 := y - 30;
MyTBox.x2 := x + 30;
MyTBox.y2 := y + 30;
if FindColor(x,y,color,MyTBox.x1,MyTBox.y1,MyTBox.x2,MyTBox.y2) then
result := true;
end;

Procedure FindColorBoxIt;
var
Tx, Ty, Rock : Integer;
begin
SetArrayLength(MyTBox,0)
If FindColorSpiralTolerance(x, y, 2370383, MSX1, MSY1, MSX2, MSY2, 5) then
GetMousePos(Tx, Ty);
If FindColorInBox(Tx, Ty, 2370383) then
begin
Rock := BitmapFromString(30, 30, '');
CopyClientToBitmap(Rock, 0, 0, 30, 30);
SetTargetBitmap(Rock);
end;
If FindBitmapIn(Rock, x, y, MSX1, MSY1, MSX2, MSY2) then
MMouse(x, y, 1, 1);
Writeln('Found Boxed Bitmap at '+IntToStr(Tx)+' X, and '+IntToStr(Ty)+' y.');
Terminatescript;
If Not FindBitmapToleranceIn(I, x, y, MSX1, MSY1, MSX2, MSY2, 5) then
Writeln(' NotFound');
Terminatescript;
end;

begin
FindColorBoxIt;
end.
it complies but i always get a runtime error, Do i have to define my array?

i know this is kinda rubbishy but i cant get to grips with the whole tpa thing.
This is meant to find an iron ore filled rock, box the rock or most of it,
make a bitmap of that box and use that so prevent color changes and use a type of auto coloring.

could someone point me in the right direction concerning tpa's and tbox's cos i read n3ss and infantry's tut but im still like ???…..

thanks

~Spaz

bullzeye95

2008-02-23 09:31:33

A TBox isn't an array, therefor you don't need the SetLength ;)

n3ss3s

2008-02-23 16:28:57

SetArrayLength(MyTBox,0)


As BullZeye said, remove it - that is also the problem.

Sorry if that was what you meant bullzeye…

bullzeye95

2008-02-23 20:25:09

Oh, yes, sorry, I meant to say you don't need the SetArrayLength :)

[S]paz

2008-02-24 10:59:26

ok thanks this will be fun….

~Spaz

[S]paz

2008-03-05 13:23:30

hmm ok still need help
i took out the setarraylength but i still get a runtime error

{.Include SRL/SRL.scar}
var
x, y : Integer;
MyTBox : TBox;

function FindColorInBox(x,y,color : integer) : boolean;
begin
MyTBox.x1 := x - 30;
MyTBox.y1 := y - 30;
MyTBox.x2 := x + 30;
MyTBox.y2 := y + 30;
if FindColor(x,y,color,MyTBox.x1,MyTBox.y1,MyTBox.x2,MyTBox.y2) then
result := true;
end;

Procedure FindColorBoxIt;
var
Tx, Ty, Rock : Integer;
begin
If FindColorSpiralTolerance(x, y, 2370383, MSX1, MSY1, MSX2, MSY2, 5) then
GetMousePos(Tx, Ty);
If FindColorInBox(Tx, Ty, 2370383) then
begin
Rock := BitmapFromString(15, 15, '');
CopyClientToBitmap(Rock, 0, 0, 15, 15);
SetTargetBitmap(Rock);
end;
If FindBitmapIn(Rock, x, y, MSX1, MSY1, MSX2, MSY2) then//heres the runtime error
MMouse(x, y, 1, 1);
Writeln('Found Boxed Bitmap at '+IntToStr(Tx)+' X, and '+IntToStr(Ty)+' y.');
Terminatescript;
If Not FindBitmapToleranceIn(Rock, x, y, MSX1, MSY1, MSX2, MSY2, 5) then
Writeln(' NotFound');
Terminatescript;
end;

begin
FindColorBoxIt;
end.

whats wrong with that~??

Successfully compiled
[Runtime Error] : Exception: Access violation at address 007261C2 in module 'scar.exe'. Read of address 00000000 in line 28 in script

:S:S

~Spaz

FrÕzÑ_§ÕµL

2008-03-05 17:56:05

If FindColorInBox(Tx, Ty, 2370383) then
begin
Rock := BitmapFromString(15, 15, '');
CopyClientToBitmap(Rock, 0, 0, 15, 15);
SetTargetBitmap(Rock);
end;
If FindBitmapIn(Rock, x, y, MSX1, MSY1, MSX2, MSY2) then

Well if the color isn't found in the box, then it still continues, but isn't rock empty? So its trying to do FindBitmapIn(empty, x, y, MSX1, MSY1, MSX2, MSY2) which gives you a violation?

I take it you thought it would always be found, but you forget about tol. So you should (maybe, I'm at school havn't got time to think) do:

If FindColorSpiralTolerance(x, y, 2370383, MSX1, MSY1, MSX2, MSY2, 5) then
If FindColorInBox(TX, TY, GetColor(x, y)) then
begin
Rock := BitmapFromString(15, 15, '');
CopyClientToBitmap(Rock, 0, 0, 15, 15);
SetTargetBitmap(Rock);
end;
If FindBitmapIn(Rock, TX, TY, MSX1, MSY1, MSX2, MSY2) then

[S]paz

2008-03-05 18:14:13

ahhhh ok, i was using this principle for autocoloring, making a bmp of say an iron rock, so that it would always find if it was present cos its the same session so no color changes and all that. Also its something new that i dont know :P

~Spaz

FrÕzÑ_§ÕµL

2008-03-05 18:30:05

Yea, the color doesn't change, but since you are finding with tol it may not be found as 2370383, so using GetColor means that it gets the exact color that is there currently. Thats autocoloring I gues… I don't use it lol.

My new tree finder is just basic, searches for a default color, if found then it checks if two other colors are in a 20/40 square pixel area with where the default color as found. The does IsUpText etc. Also starts at 0 tol and finishes at 10 (finds about 1, 2 or 3 tol). Better than FindObj though because grass won't be checks as grass doesn't have the 3 colors of trees, only one at a time :p Still use FindObj as a backup if enabled by the user though lol.

Gu3st...

2008-03-06 03:07:20

You can also use IntToBox(x1, y1, x2, y2 : Integer);
btw, Setupsrl?
try this:
{.Include SRL/SRL.scar}
var
x, y, rock : Integer;
MyTBox : TBox;

function FindColorInBox(x,y,color : integer) : boolean;
begin
MYTBox := IntToBox(x - 30, y - 30, x + 30, y + 30);
if FindColor(x,y,color,MyTBox.x1,MyTBox.y1,MyTBox.x2,MyTBox.y2) then
result := true;
end;

Procedure FindColorBoxIt;
var
Tx, Ty, Rock : Integer;
begin
If FindColorSpiralTolerance(x, y, 2370383, MSX1, MSY1, MSX2, MSY2, 5) then
GetMousePos(Tx, Ty);
If FindColorInBox(Tx, Ty, 2370383) then
begin
CopyClientToBitmap(Rock, 0, 0, 15, 15);
SetTargetBitmap(Rock);
end;
If FindBitmapIn(Rock, x, y, MSX1, MSY1, MSX2, MSY2) then//heres the runtime error
MMouse(x, y, 1, 1);
Writeln('Found Boxed Bitmap at '+IntToStr(Tx)+' X, and '+IntToStr(Ty)+' y.');
Terminatescript;
If Not FindBitmapToleranceIn(Rock, x, y, MSX1, MSY1, MSX2, MSY2, 5) then
Writeln(' NotFound');
Terminatescript;
end;

begin
setupsrl;
Rock := BitmapFromString(15, 15, '');
FindColorBoxIt;
end.

ZephyrsFury

2008-03-06 03:24:24

You've set the target bitmap to 'Rock' which is only 15 x 15 pixels. Then you try to find a bitmap is the mainscreen(MSX1, MSY1, etc.). which is much larger than 15 x 15 pixels. Thats the cause of your access violation error.

I understand what you're trying to do and I think you don't need the SetTargetBitmap.

[S]paz

2008-03-07 16:08:43

wait, i undertand everyones comment (btw i fixed it )but the bitmpa im getting is 15 X 15, ok but im searching for that bitmap in the MS, therefore its no different to any other bitmap that i could have picked and found??

i know that makes no sense so:
i make a bitmap 15 X 15 and use that bitmap to find the object in the MS
OR
it auto takes the bitmap and saves it and then finds it in the MS,

isnt that the same??? :S:S and also

BitmapToString(Rock);
does that do what i want it to? i want to paste the bitmap string in the debug, so i want to paste
rock := BitmapFromString 'jnfskhgfsihiosehtgioshui'

~Spaz