SRL Archive - SRL Suggestions

findobj: Warning! You passed a wrong ys to a finder function


sickle

2012-10-12 17:11:31

For more extensive discussion of this minor issue: http://villavu.com/forum/showthread.php?p=1110192

This is the error message: Warning! You passed a wrong ys to a finder function: -5. That is below 0, thus out of bounds. Setting the value to 0 for now.

MasterBB has deduced and even made a Youtube video of the issue here.

Can someone please take a look at fix the flaw in the function design? Or at least for now disable the warning message that clogs up the message box?

masterBB

2012-10-12 17:12:58

If any srl dev says they will use my fix, I can fix it and improve the function. Git is not an option for me atm.

masterBB

2012-10-13 11:09:11

Could anyone test this:
function FindObjEx(var cx, cy: Integer; Text: TStringArray; Color: TIntegerArray;
Tol, Step, xs, ys, xe, ye: Integer): Boolean;
var
MidX, MidY, i, j, k, x, y, width, height, HalfWidth, HalfHeight: Integer;
ColorFound: Boolean;
SearchBoxes: Array of Array of TBox;
p: TPointArray;
begin
Result := False;

//check for all the colors
for i := 0 to (GetArrayLength(Color)-1) do
if (FindColorSpiralTolerance(cx, cy, Color[i], xs, ys, xe, ye, Tol)) then
begin
ColorFound := True;
Break;
end;

if not(ColorFound) then
Exit; //None of the colors could be found on screen

//Start coordinates
MidX := Round((xe - xs) / 2);
MidY := Round((ye - ys) / 2);

//width and height in boxes
Width := Ceil(abs(xe - xs) / 2 / Step - 0.5) * 2 + 1;
Height := Ceil(abs(ye - ys) / 2 / Step - 0.5) * 2 + 1;

SetLength(SearchBoxes, Width);

HalfWidth := Floor(Width / 2);
HalfHeight := Floor(Height / 2)

for x := -1 * HalfWidth to HalfWidth do
begin
SetLength(SearchBoxes[x + HalfWidth], Height);
for y := -1 * HalfHeight to HalfHeight do
SearchBoxes[x + HalfWidth][y + HalfHeight] := IntToBox(
Max(xs, xs + Round(MidX + ((x - 0.5) * Step))),
Max(ys, ys + Round(MidY + ((y - 0.5) * Step))),
Min(xe, xs + Round(MidX + ((x + 0.5) * Step))),
Min(ye, ys + Round(MidY + ((y + 0.5) * Step))));
end;

p := TPAFromBox(IntToBox(0, 0, Width-1, Height-1));
SortTPAFrom(p, Point(floor(Width / 2), floor(Height / 2)));

for k := 0 to High(Color) do
for j := 0 to High(p) do
begin
if (FindColorTolerance(cx, cy, Color[k], SearchBoxes[p[j].x][p[j].y].x1,
SearchBoxes[p[j].x][p[j].y].y1, SearchBoxes[p[j].x][p[j].y].x2,
SearchBoxes[p[j].x][p[j].y].y2, Tol)) then
begin
MMouse(cx, cy, 3, 3);
If (WaitUptextMulti(Text, 300)) then
begin
GetMousePos(cx, cy);
Result := True;
Exit;
end;
end;
end;
end;

Just replace the function in object.simba

BraK

2012-10-13 11:12:45

If you get a few good test on it I'll put it in my Git and push it. From there it'll be up to the Devs to grab it.

masterBB

2012-10-13 11:14:51

Riwu thought me git. I am able to create a pull request myself now ^^. I got one waiting for you on srl btw.

masterBB

2012-10-22 05:45:43

https://github.com/SRL/SRL-5/pull/94