Results 1 to 6 of 6

Thread: Need Help With Another Function!

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

    Default Need Help With Another Function!

    lol here comes another one...

    I'm trying to make a function that returns false until it opens a door. Since the door can be open or closed, if it is closed and it opens it, the function will return true. If the door is open and the function closes it, it returns false. The call is a while loop that goes until it is true, so no matter what, the door should get opened up before the script continues past the call to the function.

    Anyways, the problem I am having is: It right clicks the door fine, but it keeps returning that the door wasn't there when the door is Open. When the door is closed, the script works perfectly. It's as if it cannot read the Close text in the right click menu. Also, if i switch close and open, close works and open doesn't...

    Here's my code for the function:

    SCAR Code:
    function FindDoor() : boolean;
    var
       MyTPA : TPointArray;
       x,y,i : Integer;
    begin
         writeln('Looking for door...');
         writeln('Trying first color');
         FindColorsSpiralTolerance(234,153,MyTPA, 3293259, 0, 20, 500, 330, 10);
         if Length(MyTPA) = 0 then
         begin
              writeln('Trying second color');
              FindColorsSpiralTolerance(234,153,MyTPA, 3754069, 0, 20, 500, 330, 10);
              if Length(MyTPA)=0 then
              begin
                   writeln('Trying thrid color');
                   FindColorsSpiralTolerance(234,153,MyTPA, 5532284, 0, 20, 500, 330, 10);
                   if Length(MyTPA)=0 then
                      begin
                           writeln('Trying fourth color');
                           FindColorsSpiralTolerance(234,153,MyTPA, 2963779, 0, 20, 500, 330, 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(['Church', 'door']))then
              begin
                   GetMousePos(x,y);
                   Mouse(x,y,3,3,False);
                   if (ChooseOption('pen'))then
                   begin
                        writeln('The door was closed and I opened it...')
                        Result := True;
                        Exit;
                   end
                   else if(ChooseOption('lose'))then
                   begin
                        writeln('The door was open and I closed it...');
                        if FindDoor then
                        begin
                              Result := False;
                              Exit;
                        end;
                   end
                   else
                   begin
                        writeln('The door was not found!');
                        if FindDoor then
                        begin
                              Result := False;
                              Exit;
                        end;
                   end;
              end;
              Wait(350+random(350));
         end;
    end;

    And the call to the function:

    SCAR Code:
    while not (FindDoor) do
        begin
             writeln('Trying again...');
        end;

    And the output:

    Code:
    The door was not found!
    Trying again...
    Looking for door...
    Trying first color
    Color found!
    The door was not found!
    Trying again...
    Looking for door...
    Trying first color
    Color found!
    The door was not found!
    (And so on.....)
    Thanks for all your help today guys!
    Last edited by scuz 10; 08-27-2009 at 01:32 PM.

  2. #2
    Join Date
    Feb 2009
    Posts
    1,447
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    else if(ChooseOption('lose'))then              
    begin                    
      writeln('The door was open and I closed it...');                    
      if FindDoor then                    
      begin                          
        Result := False;                          
        Exit;                    
      end;              
    end
    else              
    begin                    
      writeln('The door was not found!');                    
      if FindDoor then                    
      begin                          
        Result := False;                          
        Exit;                    
      end;              
    end;

    This isnt necesary. If the uptext is door and theres no option to open then its already opened.

    Just remove that and it should work.

    Also, add some wait time after you right click because the choose option menu takes time to load.

    Make sure you wait like 300 ms everytime you right click something and want to choose an option.
    Last edited by TRiLeZ; 08-27-2009 at 01:43 PM.

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

    Default

    Quote Originally Posted by TRiLeZ View Post
    SCAR Code:
    else if(ChooseOption('lose'))then              
    begin                    
      writeln('The door was open and I closed it...');                    
      if FindDoor then                    
      begin                          
        Result := False;                          
        Exit;                    
      end;              
    end
    else              
    begin                    
      writeln('The door was not found!');                    
      if FindDoor then                    
      begin                          
        Result := False;                          
        Exit;                    
      end;              
    end;

    This isnt necesary. If the uptext is door and theres no option to open then its already opened.

    Just remove that and it should work.

    Also, add some wait time after you right click because the choose option menu takes time to load.

    Make sure you wait like 300 ms everytime you right click something and want to choose an option.
    I see what you're saying, but if the door is already open how will my script know that? This function would just keep looping forever. I set that up so that if it was open or closed, the function wouldnt return true until the door was opened.

  4. #4
    Join Date
    Feb 2009
    Posts
    1,447
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Before:
    SCAR Code:
    end;          
    Wait(350+random(350));

    Put Exit;

    That would mean scar stops searching for the door because it already found it.

    Before the Exit put
    Result := True;

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

    Default

    Quote Originally Posted by TRiLeZ View Post
    Before:
    SCAR Code:
    end;          
    Wait(350+random(350));

    Put Exit;

    That would mean scar stops searching for the door because it already found it.

    Before the Exit put
    Result := True;
    Wouldn't that make the function return true regardless of if the door was open or closed?

    When I run it with that edit it says

    Code:
    Color found!
    Successfully executed

  6. #6
    Join Date
    Feb 2009
    Posts
    1,447
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by scuz 10 View Post
    Wouldn't that make the function return true regardless of if the door was open or closed?

    When I run it with that edit it says

    Code:
    Color found!
    Successfully executed
    If it finds the door, it WILL open it if its closed.

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
  •