Results 1 to 8 of 8

Thread: wait until certain time has passed in a procedure without stalling whole script

  1. #1
    Join Date
    Jan 2012
    Location
    in a galaxy far far away
    Posts
    371
    Mentioned
    3 Post(s)
    Quoted
    48 Post(s)

    Default wait until certain time has passed in a procedure without stalling whole script

    any tips on this? i want to run a procedure only if a certain amount of time has passed without stalling rest of my script, then reset the count after it clicks so it waits again before running spec proc.

    Simba Code:
    procedure SpecCheck;
    var
      count: Integer;
    begin
      while (Count > 60) do
      begin
      repeat
        Inc(Count);
        Wait(1000);
        WriteLn('The count is ' + IntToStr(Count) + '.'); //wait 60 seconds
      until (Count = 60)
      end
      while (Count = 60) do //after 60 seconds waited, run spec proc
      begin
        SpecialAttack;
        WriteLn('click spec');
        ClearDebug; //clear count?
        WriteLn('The count is ' + IntToStr(Count) + '.');
      end
    end;
    Last edited by chief herb; 04-09-2018 at 01:15 AM. Reason: edit
    >:)

  2. #2
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Typically I'd use a global timer for something like this.
    Simba Code:
    1. program new;
    2.  
    3. var
    4.   SpecTimer: UInt32;
    5.  
    6. procedure SpecCheck();
    7. begin
    8.   if (GetTickCount() < SpecTimer) then Exit;
    9.   //click spec. do whatever else
    10.   SpecTimer := GetTickCount() + 60000;
    11. end;
    12.  
    13. procedure Mainloop();
    14. begin
    15.   SpecCheck();
    16.   //whatever else
    17.   Wait(200);
    18. end;
    19.  
    20. begin
    21.   while True do Mainloop();
    22. end.

  3. #3
    Join Date
    Jan 2012
    Location
    Sydney, Australia
    Posts
    877
    Mentioned
    12 Post(s)
    Quoted
    368 Post(s)

    Default

    Do you want it to operate on another thread (am I saying that right?) and function independently to the rest of your script, or do you want it to be checked during your main loop like Citrus explained above?

  4. #4
    Join Date
    Jan 2012
    Location
    in a galaxy far far away
    Posts
    371
    Mentioned
    3 Post(s)
    Quoted
    48 Post(s)

    Default

    Quote Originally Posted by Dan the man View Post
    Do you want it to operate on another thread (am I saying that right?) and function independently to the rest of your script, or do you want it to be checked during your main loop like Citrus explained above?
    i think so to the 1st option? basically just want it to click over tab, check to see if spec is there and use it, if it is. then after clicking spec and clicking back tabs have it wait a certain time not making the whole script wait.
    Last edited by chief herb; 04-11-2018 at 07:38 PM.
    >:)

  5. #5
    Join Date
    Jan 2012
    Location
    in a galaxy far far away
    Posts
    371
    Mentioned
    3 Post(s)
    Quoted
    48 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    Typically I'd use a global timer for something like this.
    Simba Code:
    1. program new;
    2.  
    3. var
    4.   SpecTimer: UInt32;
    5.  
    6. procedure SpecCheck();
    7. begin
    8.   if (GetTickCount() < SpecTimer) then Exit;
    9.   //click spec. do whatever else
    10.   SpecTimer := GetTickCount() + 60000;
    11. end;
    12.  
    13. procedure Mainloop();
    14. begin
    15.   SpecCheck();
    16.   //whatever else
    17.   Wait(200);
    18. end;
    19.  
    20. begin
    21.   while True do Mainloop();
    22. end.
    does tick count or spec timer not reset? how do i reset it if not? need it to keep waiting a certain amount of time
    >:)

  6. #6
    Join Date
    Jan 2012
    Location
    Sydney, Australia
    Posts
    877
    Mentioned
    12 Post(s)
    Quoted
    368 Post(s)

    Default

    Quote Originally Posted by chief herb View Post
    does tick count or spec timer not reset? how do i reset it if not? need it to keep waiting a certain amount of time
    It does reset:
    Code:
    SpecTimer := GetTickCount() + 60000;
    This sets the next time for the SpecTimer to be measured. 60000 = 60 seconds.

    Because he hasn't declared a number for SpecTimer to trigger at, it will trigger if GetTickCount is > 0, which it would be straight away, so the SpecCheck() block would run.
    This sets the SpecTimer variable to GetTickCount (the current duration of the script) + 60 seconds, meaning if the script's elapsed time was 3000 (or 3 seconds), the timer would trigger again at 63000 (63 seconds).

  7. #7
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by Dan the man View Post
    It does reset:
    Code:
    SpecTimer := GetTickCount() + 60000;
    This sets the next time for the SpecTimer to be measured. 60000 = 60 seconds.

    Because he hasn't declared a number for SpecTimer to trigger at, it will trigger if GetTickCount is > 0, which it would be straight away, so the SpecCheck() block would run.
    This sets the SpecTimer variable to GetTickCount (the current duration of the script) + 60 seconds, meaning if the script's elapsed time was 3000 (or 3 seconds), the timer would trigger again at 63000 (63 seconds).
    This is correct, except that GetTickCount is based on your computer's uptime, not the script's. You're thinking of GetTimeRunning. Either would work for this.
    @OP, in my example the timer is set for 60 seconds. You can just change that number to whatever time you want.

  8. #8
    Join Date
    Dec 2018
    Posts
    5
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    NICE Brother i like

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
  •