Jump to content

Need some help with loop please.


Recommended Posts

18 minutes ago, FrancescoDiMuro said:

@yeto

The thread @Earthshine posted, is full of samples in which TimerInit() is used.

TimerInit() and TimerDiff() are two functions (you'd never say) used to do something every some time, or check how many seconds are passed to complete thr script, and so on.

TimerInit(), where Init stands for Initialize (?), returns an handle that can be used later with TimerDiff().

TimerDiff(), where Diff stands for Difference (?), returns how many milliseconds are passed from the TimerInit().

Let's take an example: if you'd like to know how much time the script executes all the instruction, how would you do that?

Just put a TimerInit() at the beginning of your script (a sort of "Start timer, always from 0"), and a the end of the script, you put a TimerDiff()/1000 with Round() function to see how many seconds your script took to be executed.

Look in the Help file too :)

 

I did check the help file before I asked my question. This is all it says: _Timer_Init - Returns a timestamp number (in milliseconds).

I am just not seeing why we need to know the time difference to accomplish what I am trying to accomplish. Why can't we just say that the pixel was not found so we need to look for it again and then if the pixel is found we will let yeto know by playing a wav file. What purpose does knowing the time difference play in causing the script to work. I just am not seeing what role the time difference plays in the equation. I am sure it is simple for people who know how to code to see but I am just not seeing it. Is it just a way of giving the script some type of requirement/parameter that has to be met so that the script will refresh?

"TimerInit() and TimerDiff() are two functions (you'd never say) used to do something every some time"

I know you normally wouldn't use that line but that is something I understand. Give me some more of those things you'd never say and I will probably get it.

Thank you for trying to help,
yeto

Edited by yeto
added more text
Link to comment
Share on other sites

using your code i just added some consolewrite&msgbox so we can track what actually happen , assuming the pixel never found so we can simplify code to this :-

HotKeySet("{ESC}", "On_Exit") ;quick way out if something goes wrong

#include <AutoItConstants.au3>

Global $searchforspecficpixel
Global $RefreshTimer = TimerInit()

While 1
    $TimePassed=TimerDiff($RefreshTimer)
    ConsoleWrite($TimePassed&" Milisecond passed since last TimerInit"&@crlf)
        If  $TimePassed>10000 Then ;refreshes page  ;check if 10000 msec passed yet
            $message1="Bingo;10 sec passed , lets Refresh the page"&@CRLF
            $message2="now we will reset timer by calling TimerInit again"
            MsgBox(0,"",$message1&$message2)
            $RefreshTimer = TimerInit()
        Else
        ConsoleWrite("Ten sec not passed yet"&@crlf)
        EndIf

        sleep(2000)
WEnd

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

why we use timer init&diff methods ? 
we can use sleep(10000) but the problem is the script cant do any thing in those 10000 Msec or in other word it will wait 10 sec then rechecking the pixel in your case so by using timer init&diff methods we can keep searching for the pixel  in those 10 sec and when 10 sec passed it will just refresh the page and restart the timer from 0 again and so on.

Edited by Network_Guy
Link to comment
Share on other sites

2 hours ago, Network_Guy said:

using your code i just added some consolewrite&msgbox so we can track what actually happen , assuming the pixel never found so we can simplify code to this :-

HotKeySet("{ESC}", "On_Exit") ;quick way out if something goes wrong

#include <AutoItConstants.au3>

Global $searchforspecficpixel
Global $RefreshTimer = TimerInit()

While 1
    $TimePassed=TimerDiff($RefreshTimer)
    ConsoleWrite($TimePassed&" Milisecond passed since last TimerInit"&@crlf)
        If  $TimePassed>10000 Then ;refreshes page  ;check if 10000 msec passed yet
            $message1="Bingo;10 sec passed , lets Refresh the page"&@CRLF
            $message2="now we will reset timer by calling TimerInit again"
            MsgBox(0,"",$message1&$message2)
            $RefreshTimer = TimerInit()
        Else
        ConsoleWrite("Ten sec not passed yet"&@crlf)
        EndIf

        sleep(2000)
WEnd

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

why we use timer init&diff methods ? 
we can use sleep(10000) but the problem is the script cant do any thing in those 10000 Msec or in other word it will wait 10 sec then rechecking the pixel in your case so by using timer init&diff methods we can keep searching for the pixel  in those 10 sec and when 10 sec passed it will just refresh the page and restart the timer from 0 again and so on.

Thank you so much for explaining init&diff methods. Yes, that makes sense related to allowing script to continue to work versus sleeping. I did not know that that was actually happening.

Thank you for taking time out of your day to help,
yeto  

Link to comment
Share on other sites

On 7/8/2019 at 1:48 AM, yeto said:

I need to refresh every 10 seconds until pixel is found.

This is why you need TimerInit() and TimerDiff() functions.

How does th script know how many (milli)seconds have passed when you were looking for a pixel that is not found?

You need to set a timer, and check every 10000 milliseconds, or 10 seconds, if the pixel was found.

TimerInit() starts the counter, TimerDiff() takes the difference between TimerInit() and the call of TimerDiff(), and sees how many milliseconds have passed :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

On 7/9/2019 at 12:14 AM, FrancescoDiMuro said:

This is why you need TimerInit() and TimerDiff() functions.

How does th script know how many (milli)seconds have passed when you were looking for a pixel that is not found?

You need to set a timer, and check every 10000 milliseconds, or 10 seconds, if the pixel was found.

TimerInit() starts the counter, TimerDiff() takes the difference between TimerInit() and the call of TimerDiff(), and sees how many milliseconds have passed :)

Thank you for taking time to help me understand.

One last question if you please. I was thinking that PixelSearch would search the "whole" block (x, y coordinates) before moving on to the next step timer or no timer. The page is static in my situation so the pixels aren't going to change unless the page is refreshed. Does the timer set PixelSearch to keep searching the block multiple times until the time runs out which in this case wouldn't help?

Thank you,
yeto

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...