
Originally Posted by
Coh3n
E: The error is within FindObj. Since it calls FindColorsSpiral, it will spiral out from x, y and if x and/or y is 0, it will set it to a negative number.
Like riwu said do this and you'll be fine:
Simba Code:
findObj(MSCX, MSCY, 'It', 11974591, 5);
What? Unless I got a different version of simba you can use spiral points outside the square you are searching for. Unless I understood it wrong, the error, or warning in this case, can only be achieved by setting ys to a wrong value. Here is the code that creates the error:
Units/MMLCore/finder.pas#L687: line 687
Simba Code:
procedure TMFinder.DefaultOperations(var xs, ys, xe, ye: integer);
var
w,h : integer;
begin
//...
if ys < 0 then
if WarnOnly then
begin
TClient(Client).WriteLn(Format('Warning! You passed a wrong ys to a finder function: %d. That is below 0, thus out of bounds. Setting the value to 0 for now.',[ys]));
ys := 0;
end else
raise Exception.createFMT('You passed a wrong ys to a finder function: %d. That is below 0, thus out of bounds.',[ys]);
//...
end;
The FindColorSpiralTolerance function calls this before it uses the center x and center y (cx, cy). Therefore the cx and cy in the FindColorSpiralTolerance function can't cause this error.
Also note how it is possible to use a point outside of the search area, this can be useful in some cases. Proof:
master/Units/MMLCore/finder.pas#L448: line 448
Simba Code:
procedure TMFinder.LoadSpiralPath(startX, startY, x1, y1, x2, y2: Integer);
var
i,c,Ring : integer;
CurrBox : TBox;
begin
i := 0;
Ring := 1;
c := 0;
CurrBox.x1 := Startx-1;
CurrBox.y1 := Starty-1;
CurrBox.x2 := Startx+1;
CurrBox.y2 := Starty+1;
if (startx >= x1) and (startx <= x2) and (starty >= y1) and (starty <= y2) then
begin;
ClientTPA[c] := Point(Startx, StartY);
Inc(c);
end;
repeat
if (CurrBox.x2 >= x1) and (CurrBox.x1 <= x2) and (Currbox.y1 >= y1) and (Currbox.y1 <= y2) then
for i := CurrBox.x1 + 1 to CurrBox.x2 do
if (I >= x1) and ( I <= x2) then
begin;
ClientTPA[c] := Point(i,CurrBox.y1);
Inc(c);
end;
if (CurrBox.x2 >= x1) and (CurrBox.x2 <= x2) and (Currbox.y2 >= y1) and (Currbox.y1 <= y2) then
for i := CurrBox.y1 + 1 to CurrBox.y2 do
if (I >= y1) and ( I <= y2) then
begin;
ClientTPA[c] := Point(Currbox.x2, I);
Inc(c);
end;
if (CurrBox.x2 >= x1) and (CurrBox.x1 <= x2) and (Currbox.y2 >= y1) and (Currbox.y2 <= y2) then
for i := CurrBox.x2 - 1 downto CurrBox.x1 do
if (I >= x1) and ( I <= x2) then
begin;
ClientTPA[c] := Point(i,CurrBox.y2);
Inc(c);
end;
if (CurrBox.x1 >= x1) and (CurrBox.x1 <= x2) and (Currbox.y2 >= y1) and (Currbox.y1 <= y2) then
for i := CurrBox.y2 - 1 downto CurrBox.y1 do
if (I >= y1) and ( I <= y2) then
begin;
ClientTPA[c] := Point(Currbox.x1, I);
Inc(c);
end;
Inc(ring);
CurrBox.x1 := Startx-ring;
CurrBox.y1 := Starty-Ring;
CurrBox.x2 := Startx+Ring;
CurrBox.y2 := Starty+Ring;
until (Currbox.x1 < x1) and (Currbox.x2 > x2) and (currbox.y1 < y1)
and (currbox.y2 > y2);
end;
edit:
But what causes the error is the question of course. Let's look into SRL itself.
master/SRL/core/object.simba: Line 326
Simba Code:
function FindObj(var cx, cy: Integer; Text: string; Color: Integer; Tol: Integer): Boolean;
begin
Result := FindObjEx(cx, cy, [Text], [Color], Tol, 50, MSX1, MSY1, MSX2, MSY2);
end;
As you can see this function uses the SRL MS coordinates. The center coordinates are passed through without touching them.
The first call too a findcolor function. Not how this one, if the MS coords are setup well can't cause an error.
master/SRL/core/object.simba: Line 254
Simba Code:
if (FindColorSpiralTolerance(cx, cy, color[b], xs, ys, xe, ye, Tol)) then
The second and last call to a FindColor function. Note how this one actually can cause a ys of less then 0? Since the step is 50, CurY is decreased with 25.
Simba Code:
if (FindColorTolerance(cx, cy, Color[b], CurX-(Step div 2), CurY-(Step div 2), CurX+(Step div 2), CurY+(Step div 2), Tol)) then
So can CurY be less then Step? Yes, actually it can. There is a design flaw in the function. Mystery solved.