Jump to content
fewtcher

Repeat until condition?

Recommended Posts

Hello, so I'm trying to make a script for one browser game but I am stuck because I don't know how to define the "repeat until" command. Here's my script:

 

program FindItem;

var

x1, y1: Integer;

begin

wait(5000);

repeat

if FindColor(x1, y1, 8077125, 940, 375, 1000, 430) then

begin

WriteLn('found it')

MoveMouse(x1, y1);

ClickMouse(x1, y1, false);

end else

begin

WriteLn('couldnt find it, trying again');

wait(500);

MoveMouse(950, 325);

ClickMouse(950, 325, false);

wait(200);

MoveMouse(1050, 325);

ClickMouse(1050, 325, false);

until WriteLn = (found it);

end;

end.

 

So basically I want it to look like this:

Repeat

Action1

Action2

Until Action1 is complete/true (I don't know).

 

If it still doesn't make sense here's an explanation - so the first action is the script searching for an item (color) in a small area of the screen. If it doesn't find it the second action is to refresh the window with the items (items change when their window is refreshed). I want the script to repeat itself until it finds the item (complete action 1). I hope that's a detailed enough explanation... I just don't know how to define the "Until" condition...

 

PS: Ok found how to do it. I added a new integer and just changed the first action from clicking (I don't need it to click) to increasing the value of the integer to 1. So if the action is executed my integer will change it's value to 1 and the script will stop ^^ Also saw that I put "until" before the 1st "end" while I should've put it after it.

 

program FindItem;

var

x1, y1: Integer;

i: Integer;

begin

wait(500);

repeat

if FindColor(x1, y1, 8077125, 940, 375, 1000, 430) then

begin

WriteLn('found it')

Inc(i);

end else

begin

WriteLn('couldnt find it, trying again');

wait(500);

MoveMouse(950, 325);

ClickMouse(950, 325, false);

wait(200);

MoveMouse(1050, 325);

ClickMouse(1050, 325, false);

end;

until i = 1;

end.

Edited by fewtcher
Link to comment
Share on other sites

Yes, you've solved it nicely ;)

 

Remember to format your code so that when it becomes larger it is easier to find faults and fix them. I also recommend you post with the

 tags... You can find them as a "#" in the toolbar when creating a Thread. Best of luck programming.

[code]program FindItem;

var
x1, y1: Integer; 
i: Integer;

begin
 Wait(500);
 repeat
   if FindColor(x1, y1, 8077125, 940, 375, 1000, 430) then
   begin
     WriteLn('found it') 
     Inc(i);
   end else
   begin
     WriteLn('couldnt find it, trying again'); 
     Wait(500); 
     MoveMouse(950, 325);
     ClickMouse(950, 325, false); 
     Wait(200); 
     MoveMouse(1050, 325);
     ClickMouse(1050, 325, false); 
   end; 
 until (i = 1); 
end.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...