Results 1 to 24 of 24

Thread: Passed a wrong ys to a finder function??

  1. #1
    Join Date
    Mar 2012
    Posts
    182
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default Passed a wrong ys to a finder function??

    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?

    Simba Code:
    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;
    Last edited by sickle; 10-09-2012 at 01:00 AM.

  2. #2
    Join Date
    Jun 2012
    Posts
    2,182
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Can you show us your function?
    Thx Euphemism and Vinyl for the awesome siggy and avatar!

  3. #3
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    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.

  4. #4
    Join Date
    Mar 2012
    Posts
    182
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by BMWxi View Post
    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
    Last edited by sickle; 10-09-2012 at 02:48 AM.

  5. #5
    Join Date
    Jun 2007
    Location
    La Mirada, CA
    Posts
    2,484
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    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.
    Progress Report:
    *
       _____________
      |                    |
      |                    |
      |                    |
      |                    |
      ______________


    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)
    Last edited by Coh3n; 10-09-2012 at 12:00 PM.

    "Failure is the opportunity to begin again more intelligently" (Henry Ford)


  6. #6
    Join Date
    Mar 2012
    Posts
    182
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by HyperSecret View Post
    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.

  7. #7
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Quote Originally Posted by sickle View Post
    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 , here it is http://villavu.com/forum/showthread.php?t=90681

  8. #8
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Simba Code:
    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;

    Forum account issues? Please send me a PM

  9. #9
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    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.

  10. #10
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    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.

  11. #11
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    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:
    Simba Code:
    findObj(MSCX, MSCY, 'It', 11974591, 5);
    Last edited by Coh3n; 10-09-2012 at 12:33 PM.

  12. #12
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    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) ?
    Working on: Tithe Farmer

  13. #13
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    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.
    Last edited by masterBB; 10-09-2012 at 01:04 PM.
    Working on: Tithe Farmer

  14. #14
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    1,252
    Mentioned
    1 Post(s)
    Quoted
    22 Post(s)

    Default

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

  15. #15
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

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

  16. #16
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Lol, did I not say the problem was in FindObj? I just didn't explain myself well.
    With a different reason. Cause it is valid to give a negative x and y.
    Working on: Tithe Farmer

  17. #17
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    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.

  18. #18
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Working on: Tithe Farmer

  19. #19
    Join Date
    Mar 2012
    Posts
    182
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    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.

    Quote Originally Posted by masterBB View Post
    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.
    Last edited by sickle; 10-12-2012 at 02:11 AM.

  20. #20
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

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

  21. #21
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    In my second post and youtube video I explain it is a warning from a badly written function.
    Working on: Tithe Farmer

  22. #22
    Join Date
    Aug 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

  23. #23
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    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.
    Working on: Tithe Farmer

  24. #24
    Join Date
    Mar 2012
    Posts
    182
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •