Jump to content
briang123

How do you implement a timer condition?

Recommended Posts

briang123
$test = True
while($test)
    $BananaPixel = PixelSearch(903, 24, 1250, 157, 0xD9D70C, 1)
    if NOT(@error) Then
        LC($BananaPixel[0], $BananaPixel[1] + 250)
        $test = False
    EndIf
WEnd

#if BananaPixel isnt found in 15 seconds, do: 'LC(993,34)' then search for $BananaPixel again

Func LC($x, $y)
   MouseClick("left", $x, $y, 1, 3)
EndFunc

My code above tries to search for a pixel for an infinite amount of time until it is found. Once it is found, it clicks the x coordinate of the pixel and the y coordinate + 250 of the pixel, then the while loop stops. I don't know how to use the timer functions to make a condition for my code that "if I cannot find the BananaPixel in 15 seconds, do a left click at x,y coordinates then search for BananaPixel again. Any help would be greatly appreciated! Thanks.

Share this post


Link to post
Share on other sites
FrancescoDiMuro
Posted (edited)

Good morning @briang123, and welcome to the AutoIt forum :)
Let's comment a bit what your script does :)

$test = True
while($test) ; While 1
    $BananaPixel = PixelSearch(903, 24, 1250, 157, 0xD9D70C, 1) ; Search for the Pixel
    if NOT(@error) Then                                         ; If the Pixel has been found, then...
        LC($BananaPixel[0], $BananaPixel[1] + 250)
        $test = False
    EndIf                                                       ; Nothing ELSE...
WEnd

; if BananaPixel isnt found in 15 seconds, do: 'LC(993,34)' then search for $BananaPixel again

Func LC($x, $y)
   MouseClick("left", $x, $y, 1, 3)
EndFunc

Do you know about "If...Else" statement? :)
You can take a look here.

About the timer, indeed, you should take a look at TimerInit() and TimerDiff() functions, which you can find here:

Local $test = True, _
      $hTimer                                                       ; Declare the Timer


$hTimer = TimerInit()                                               ; Start the Timer

while($test)                                                        ; While 1
    $BananaPixel = PixelSearch(903, 24, 1250, 157, 0xD9D70C, 1)     ; Search for the Pixel
    If Not (@error) Then                                            ; If the Pixel has been found, then...
        LC($BananaPixel[0], $BananaPixel[1] + 250)                  ; Left Click
        $test = False                                               ; ExitLoop
    Else
        If TimerDiff($hTimer) >= 15000 Then                         ; If the Timer limit of 15 seconds has been reached, then...
            ConsoleWrite(Round(TimerDiff($hTimer)/1000, 0) & " seconds limit reached!" & @CRLF & _
                         "The timer will be restarted!" & @CRLF)
            ; LC(1, 2)                                              ; LC(x, y)
            $hTimer = TimerInit()                                   ; Restart the timer
        Else
            ContinueLoop                                            ; ELSE, Continue the While loop
        EndIf
    EndIf
WEnd

; if BananaPixel isnt found in 15 seconds, do: 'LC(993,34)' then search for $BananaPixel again

Func LC($x, $y)
   MouseClick("left", $x, $y, 1, 3)
EndFunc

If you have question about this, feel free to ask :)

Best Regards.

Edited by FrancescoDiMuro
  • Like 1

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

ALWAYS GOOD TO READ:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
Melba23

briang123,

By the name of your variable ($BananaPixel) you might well be looking to automate a game and you have possibly not read the Forum rules since your arrival on the forum. Please do read them - particularly the bit about not discussing game automation - before you post again.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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

  • Similar Content

    • Pagi
      By Pagi
       
      <a href="index.php=4143b27b41db0a40c499202865c3e24d" class="menuitem " target="\_self"> "Menu Item 1" </a>
      Can you tell me if it´s possible to click this menu button? If yes, how? Cause I have no idea, I think i should use _IETagNameGetCollection
    • mar3011
      By mar3011
      hello, I want to set in the inputbox field random key from the keyboard to which the function will be assigned, for example F4 function start notepad ALT + A function start notepad for one function. Thank you for any help.  
    • JuanFelipe
      By JuanFelipe
      Cambiar a español Hello friends, I need help with a problem I have, I want to know if there is any way to update a GUI already running, that is I have a GUI of a certain size and with a button I would like to enlarge it:
      example: $ form1 = GUICreate ("", 200,100,0,0)   When you press the button, the gui increases its size, and actuates the new size.
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • santoshM
      By santoshM
      Dear friends i am facing a problem , i have created a window in autoit some time it is moving with the mouse curser even if iam not clicking the window 
×