briang123 Posted June 27, 2018 Posted June 27, 2018 $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.
FrancescoDiMuro Posted June 27, 2018 Posted June 27, 2018 (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 June 27, 2018 by FrancescoDiMuro briang123 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Moderators Melba23 Posted June 27, 2018 Moderators Posted June 27, 2018 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now