Results 1 to 7 of 7

Thread: What's Wrong With My Function?

  1. #1
    Join Date
    Aug 2009
    Posts
    164
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default What's Wrong With My Function?

    I'm using this function to open a gate that's part of a fence. It finds the gate, right clicks it, selects open, but then returns false!? What's wrong?

    The function:

    SCAR Code:
    function FindGate() : boolean;
    var
       MyTPA : TPointArray;
       x,y,i : Integer;
    begin
         writeln('Looking for gate...');
         writeln('Trying first color');
         FindColorsSpiralTolerance(284,202,MyTPA, 3292991, 0, 20, 547, 464, 10);
         if Length(MyTPA) = 0 then
         begin
              writeln('Trying second color');
              FindColorsSpiralTolerance(284,202,MyTPA, 2041383, 0, 20, 547, 464, 10);
              if Length(MyTPA)=0 then
              begin
                   writeln('Trying thrid color');
                   FindColorsSpiralTolerance(284,202,MyTPA, 2700084, 0, 20, 547, 464, 10);
                   if Length(MyTPA)=0 then
                      begin
                           writeln('Trying fourth color');
                           FindColorsSpiralTolerance(284,202,MyTPA, 4280914, 0, 20, 547, 464, 10);
                      end;
              end;
         end;
         writeln('Color found!');
         for i:= 0 to High(MyTPA)do
         begin
              MMouse(MyTPA[i].x, MyTPA[i].y,3,3);
              if(IsUpTextMultiCustom(['Open']))then
              begin
                   GetMousePos(x,y);
                   Mouse(x,y,3,3,False);
                   if not(ChooseOption('Open'))then
                   begin
                        FindGate;
                        writeln('Point chosen incorrectly...trying agian...')
                   end
                   else
                   begin
                        writeln('Gate opened successfully!');
                        Result:=true;
                        Exit;
                   end;
              end;
              Wait(350+random(350));
         end;
    end;

    Call to function:
    SCAR Code:
    while not (FindGate) do
        begin
             FindGate;
             writeln('trying again');
        end;

    Any ideas?

  2. #2
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Try changing
    SCAR Code:
    while not (FindGate) do
        begin
             FindGate;
             writeln('trying again');
        end;
    to
    SCAR Code:
    while not (FindGate) do
        begin
             writeln('trying again');
        end;

  3. #3
    Join Date
    Aug 2009
    Posts
    164
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Still does'nt work

    when I run it and it finds the gate, i get:

    Code:
    Trying first color
    Color found!
    Gate Found Successfully!
    Point chosen incorrectly...trying again...

  4. #4
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You move the mouse to where you think the gate is at. If you get the correct uptext, you get the mouse position, then you click at a random location around there because you have:

    SCAR Code:
    Mouse(x,y,3,3,False);

    Change that to
    SCAR Code:
    Mouse(x,y,0,0,False);

    And that will ensure that it right clicks at the location you wanted.


    You also might want to try a WaitOption('text',500+random(200)); in case of lag.

    You also have an infinite loop because if it doesn't choose the option, you call the function again (recursion) every time.
    Last edited by JAD; 08-27-2009 at 06:20 AM.

  5. #5
    Join Date
    Aug 2009
    Posts
    164
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    My problem isn't finding the gate...it finds it and opens it fine...the problem is when it correctly finds Open it repeats the function

  6. #6
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    SCAR Code:
    writeln('Point chosen incorrectly...trying agian...');
    if FindGate then
    begin
      Result := True;
      Exit;
    end;

    A function calling itself doesn't mean it just starts over again, it actually means it is executed in itself. So you need to set the result there as well.

  7. #7
    Join Date
    Aug 2009
    Posts
    164
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    SCAR Code:
    writeln('Point chosen incorrectly...trying agian...');
    if FindGate then
    begin
      Result := True;
      Exit;
    end;

    A function calling itself doesn't mean it just starts over again, it actually means it is executed in itself. So you need to set the result there as well.
    THANKS! it works perfectly now

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
  •