Jump to content
xxAx

Does the wait of one procedure conflict with wait in another procedure?

Recommended Posts

Hello, I'm pretty new to this Scar. So far I've watched and read tutorials, and come up with this so far.

What it should do is:

Search for the color I've picked (3038369), and when it shows, it should click it. (This Works)

Second of all, it should hold me online with some text it writes every ~9 minute. (Couldn't figure out how I could set some variables with text and then a randomizer picks between the variables.) So it only writes one text. (..)

I want the script to look for the color every 10 seconds, and if it's been clicked, is it possible to set the wait up so it wont check for another 55 minutes, and then go down to 10 seconds again?

When the script is looking for the color, it should also keep me online with the text typing every 9~ minutes. How is that possible to run these two "scripts" with these intervals?

 

program FindTimeBox;

var
x,y: Integer;

const
TimeBoxColor= 3038369; //Set the color

procedure LeftClick;
begin
 ClickMouse(x, y, mbleft);
end;

procedure Chat;   //This doesnt work
begin
 Wait(360000+random(180000))
 TypeText('.');
 Wait(500);
 TypeText(Chr(13));
end;

begin
repeat
Wait(5000);
if(FindColor(x,y,TimeBoxColor,0,0,600,600)) then
begin
 ClearDebug;
 Writeln('Found Timebox');
 LeftClick;
 Wait(2000);
 ClearDebug;
end else
 ClearDebug;
 Writeln('Did not find any Timebox'); 
 Wait(2000);
 ClearDebug;
 //This works
 TypeText('..');
 TypeText(Chr(13));
 WriteLn('Typed Text');
until(false);
end.

Link to comment
Share on other sites

At first it sounded like you were trying to multithread but then I realized you are just trying to structure a detailed repeating loop with a lot of conditions and such

 

This code is untested but looks solid to me

 

procedure RandomPhrase;
begin
 case (Random(5)) of  // number of phrases ( # )
   0: WriteLn('Phrase 1');            // Phrase 0:
   1: WriteLn('Phrase 2');
   2: WriteLn('Phrase 3');
   3: WriteLn('Phrase 4');
   4: WriteLn('Phrase 5');            // Phrase (# - 1):
 end;
end;

procedure MainLoop;
var
 Found: Boolean;
 X, Y, T, Nc, Np: Integer;
begin
 repeat
   Found := FindColor(X, Y, 3038369, 0, 0, 600, 600);
   if (Found) then
     ClickMouse(x, y, mbLeft);
   T := GetSystemTime; // Begin recording time
   Nc := 0; // Current resultant of dividing by 9 minutes
   Np := 0; // Previous resultant of dividing by 9 minutes
   if (Found) then
   repeat
     Wait(100);
     Nc := Round((GetSystemTime - T) / (9 * 1000 * 60)); //Time passed divided by 9 minutes
     if (Nc <> Np) then
     begin
       Np := Nc; // Set previous resultant to current resultant
       RandomPhrase;
     end;   
   until (T < (GetSystemTime - (55 * 60 * 1000))); // 55 minutes x 60 seconds x 1000 miliseconds
   if (not (Found)) then
     Wait(10000);
 until (False);  
end;

begin
 MainLoop;
end.

Link to comment
Share on other sites

Thank you! I will give it a go, and reply back. :-)

 

- - - Updated - - -

 

So, I tried to understand the script. I'll try to break it up so I can understand it better.

procedure RandomPhrase;
begin
 case (Random(5)) of  // number of phrases ( # )
   0: WriteLn('Phrase 1');            // Phrase 0:
   1: WriteLn('Phrase 2');
   2: WriteLn('Phrase 3');
   3: WriteLn('Phrase 4');
   4: WriteLn('Phrase 5');            // Phrase (# - 1):
 end;
end;

I think I understand this. You create 5 possibilities for an outcome in the debug console. Correct?

Well, it's almost what I wanted. These 5 possibilities should be TypeText('Phrase1-5') and TypeText(Chr(13));

Would it be corrected to?

procedure RandomPhrase;
begin
 case (Random(5)) of  // number of phrases ( # )
   0: TypeText('Phrase 1');            // Phrase 0:
   1: TypeText('Phrase 2');
   2: TypeText('Phrase 3');
   3: TypeText('Phrase 4');
   4: TypeText('Phrase 5');            // Phrase (# - 1):
 end;
end;

 

The next procedure is MainLoop.

This is where the "magic" happens, so when the color comes up it will press it and add the 55 minutes till next check? Correct?

procedure MainLoop;
var
 Found: Boolean;
 X, Y, T, Nc, Np: Integer;
begin
 repeat
   Found := FindColor(X, Y, 3038369, 0, 0, 600, 600);
   if (Found) then
     ClickMouse(x, y, mbLeft);
   T := GetSystemTime; // Begin recording time
   Nc := 0; // Current resultant of dividing by 9 minutes
   Np := 0; // Previous resultant of dividing by 9 minutes
   if (Found) then
   repeat
     Wait(100);
     Nc := Round((GetSystemTime - T) / (9 * 1000 * 60)); //Time passed divided by 9 minutes
     if (Nc <> Np) then
     begin
       Np := Nc; // Set previous resultant to current resultant
       RandomPhrase;
     end;   
   until (T < (GetSystemTime - (55 * 60 * 1000))); // 55 minutes x 60 seconds x 1000 miliseconds
   if (not (Found)) then
     Wait(10000);
 until (False);  
end;

This is where it gets abit tricky for me. As I understand this, the script will only call the procedure RandomPhrase if the script finds the color (3038369).

(In this game I'm making the script for, you need to write something every 15-19 minutes to stay online. I've just chosen the ~9 minutes, because random.)

I want the script to write every 9+random(9minutes) meanwhile it will check for the color. When the color is found it will go "standby" the next 55 minutes and then come back and check every 10 seconds.

Mean while the RandomPhrase function will run every 9+random(9minutes).

 

Sorry for my english, I hope you understand what I wrote. And again, thank you for your help.

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