SRL Archive - Help

Passed a wrong ys to a finder function??


sickle

2012-10-08 20:16:13

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.

I think this is happening with findobj function I am using. I made to sure to have getmousepos(x,y), but still happening. This isn't interfering is what it's meant to do, but it's clogging up with the same message. How can I fix this?


procedure FindIt;
var
Xi, Yi, x: Integer;
begin
SetAngle(SRL_ANGLE_HIGH);

x := Random(8)

if FindObj(x, y, 'It', 11974591, 5) then
begin
GetMousePos(Xi, Yi);
ClickMouse2(1);

while IsMoving do
begin
Wait(250);
end;
end
else
begin
wait(800)
end;
end;

Footy

2012-10-08 20:23:22

Can you show us your function?

Ian

2012-10-08 21:49:29

The same thing happens to me when I use FindObjCustom. I posted a thread not too long ago, I think there are suggestions on it.

sickle

2012-10-08 22:44:55

From: BMWxi
The same thing happens to me when I use FindObjCustom. I posted a thread not too long ago, I think there are suggestions on it.


Do you mind posting the link? You sure made a lot of posts from "not long ago" till now, and I can't find it from a cursory search :)

HyperSecret

2012-10-08 23:52:24

Point(0,0) is the upper left of the SMART/game window. When you get this error you are passing a point that is outside/beyond this point. Make sure the points you are passing are both greater than 0.

*
_____________
| |
| |
| |
| |
______________

The * is the point you are passing to the function and the box is the screen it is trying to look in. So the point doesn't fall within the block/screen/window that is being search.

(Picture didn't turn out)

sickle

2012-10-09 06:38:09

From: HyperSecret
Point(0,0) is the upper left of the SMART/game window. When you get this error you are passing a point that is outside/beyond this point. Make sure the points you are passing are both greater than 0.

*
_____________
| |
| |
| |
| |
______________

The * is the point you are passing to the function and the box is the screen it is trying to look in. So the point doesn't fall within the block/screen/window that is being search.

(Picture didn't turn out)


I understand that, but somehow I don't see how I am doing that with the function I posted above.

Ian

2012-10-09 07:03:40

From: sickle
Do you mind posting the link? You sure made a lot of posts from "not long ago" till now, and I can't find it from a cursory search :)


Sorry about being vague :p, here it is http://villavu.com/forum/showthread.php?t=90681

Justin

2012-10-09 07:29:42


procedure FindIt;
var //
Xi, Yi, x: Integer; //Why
begin
SetAngle(SRL_ANGLE_HIGH);

x := Random(8) //Why?

if FindObj(x, y, 'It', 11974591, 5) then
begin
GetMousePos(Xi, Yi); //Why
MMouse(x, y, 3, 3);
ClickMouse2(mouse_Left);

while IsMoving do
begin
Wait(250);
end;
end
else
begin
wait(800)
end;
end;

Coh3n

2012-10-09 08:02:36

You're getting the error because you never set y, so it's automatically set to 0. Using Random(8) can give you anywhere from 0-7, which could cause the same error if the random integer happens to be 0.

riwu

2012-10-09 08:22:52

From: Coh3n
You're getting the error because you never set y, so it's automatically set to 0. Using Random(8) can give you anywhere from 0-7, which could cause the same error if the random integer happens to be 0.

He is randoming the x but the error is y. Also passing 0 to finder won't return an error i think? Based on the error y is set to -5, and y isn't declared locally (which is extremely weird), so it's probably set to -5 in some other functions.

@OP you should just set the x,y to MSCX, MSCY respectively if you want it to search from centre. And declare the variables locally. Also FindObj already returns the coordinate to the var x,y (through GetMousePos in its own function) so you dont have to call GetMousePos again.

Coh3n

2012-10-09 08:29:59

From: riwu
He is randoming the x but the error is y. Also passing 0 to finder won't return an error i think? Based on the error y is set to -5, and y isn't declared locally (which is extremely weird), so it's probably set to -5 in some other functions.
I know, I was just saying it same error is possible, but for x. Also, if they're set to 0 it may not error, I was going off of what HyperSecret said. I think you're right, though. 0, 0 should be a valid search point.

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:

findObj(MSCX, MSCY, 'It', 11974591, 5);

masterBB

2012-10-09 08:37:02

FindObj uses; function TMFinder.FindColorSpiralTolerance(var x, y: Integer; color, xs, ys, xe, ye, Tol: Integer): Boolean;

The error you see is because ys equals -5. The odd thing is though that FindObj uses MSY1, maybe you didn't run SetupSRL or set it to a different value. Could you writeln(MSY1) ?

masterBB

2012-10-09 08:51:01

From: 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:

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
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
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
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
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.

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.

P1ng

2012-10-10 02:35:04

Looks like MasterBB just logic'ed this right out of the water. Nice job :)

Coh3n

2012-10-10 08:12:52

Lol, did I not say the problem was in FindObj? I just didn't explain myself well. :p

masterBB

2012-10-10 08:45:44

From: Coh3n
Lol, did I not say the problem was in FindObj? I just didn't explain myself well. :p


With a different reason. Cause it is valid to give a negative x and y.

Coh3n

2012-10-10 08:55:04

From: masterBB
With a different reason. Cause it is valid to give a negative x and y.
Yeah, which doesn't make much sense to me. Is doesn't make sense to pass a center point that's outside the area you want to look in. Know what I mean? I guess if you wanted to start searching from a specific area, but if that were the case you shouldn't use FindColorSpiral.

masterBB

2012-10-10 11:26:27

[YOUTUBE]Z8I5Fk8hXA8[/YOUTUBE]

sickle

2012-10-11 22:01:37

From: riwu
He is randoming the x but the error is y. Also passing 0 to finder won't return an error i think? Based on the error y is set to -5, and y isn't declared locally (which is extremely weird), so it's probably set to -5 in some other functions.

@OP you should just set the x,y to MSCX, MSCY respectively if you want it to search from centre. And declare the variables locally. Also FindObj already returns the coordinate to the var x,y (through GetMousePos in its own function) so you dont have to call GetMousePos again.


Setting x,y to MSCX, MSCY still return the same error.

From: masterBB
FindObj uses; function TMFinder.FindColorSpiralTolerance(var x, y: Integer; color, xs, ys, xe, ye, Tol: Integer): Boolean;

The error you see is because ys equals -5. The odd thing is though that FindObj uses MSY1, maybe you didn't run SetupSRL or set it to a different value. Could you writeln(MSY1) ?


I do run SetupSRL in the script. MSY1 is always returned as 4.

I now locally declare y, but to the same result.

I don't understand your second post that discusses the function itself.

How would you solve the problem? It doesn't halt the function, but it seems like it makes finding objects less effective.

Ian

2012-10-11 22:12:50

For me it comes and goes. If I watch for a minute I will see it.

masterBB

2012-10-12 00:58:38

In my second post and youtube video I explain it is a warning from a badly written function.

sl3

2012-10-12 03:13:01

Is there any way to disable this warning? I tried searching through the includes hoping to comment out the line that prints this warning but I couldn't find it anywhere.

My scripts work fine but I'd rather not have this cluttering up the debug box.

masterBB

2012-10-12 06:14:20

No, an SRL developer has to fix it. There are many ways to do it, if you want you could create a thread in the suggestion area.

sickle

2012-10-12 17:12:39

Thank you masterBB. Made a suggestion post here: http://villavu.com/forum/showthread.php?p=1111463