travinia Posted March 10, 2015 Share Posted March 10, 2015 I am having trouble with one part of the code, It is made to detect a pixel on the screen that is given a set color. I want it to give 2 scripts (one if it finds the pixel, and another if it doesnt.) I have "If @error then" and the script, IF it did not find the pixel. I have "If Not @error Then" and the script, IF it found the pixel. It just seems to continue the whole script in order, ignoring the "If @error then" & "If Not @error Then" expandcollapse popupGlobal $Runner HotKeySet("{ESC}", "Terminate") HotKeySet("{F1}", "Click") Func Terminate() Exit 0 EndFunc Func Click() PixelSearch(1233, 826, 1386, 852, 0xFFCC00) If @error then MouseClick("left", 716, 698, 10) Sleep (500) Send("{a down}") Sleep (800) Send("{a up}") Sleep (500) MouseClick("left", 716, 698, 10) Sleep (500) Send("{d down}") Sleep (800) Send("{d up}") Sleep (500) MouseClick("left", 716, 698, 10) Sleep (500) EndIf If Not @error Then Sleep (500) MouseClick("left", 863, 697, 3) Sleep (500) MouseClick("left", 701, 750, 3) Sleep (500) MouseClick("left", 863, 697, 3) Sleep (500) MouseClick("left", 701, 750, 3) Sleep (500) MouseClick("left", 1095, 873, 3) Send("{@ 1}") Sleep (100) Send("{c 1}") Sleep (100) Send("{o 1}") Sleep (100) Send("{n 1}") Sleep (100) Send("{f 1}") Sleep (100) Send("{l 1}") Sleep (100) Send("{i 1}") Sleep (100) Send("{c 1}") Sleep (100) Send("{t 1}") Sleep (100) Send("{s 1}") Sleep (100) Send("{o 1}") Sleep (100) Send("{u 1}") Sleep (100) Send("{l 1}") Sleep (100) Send("{Space 1}") Sleep (100) Send("{d 1}") Sleep (100) Send("{Enter 1}") Sleep (500) Send("{@ 1}") Sleep (100) Send("{c 1}") Sleep (100) Send("{o 1}") Sleep (100) Send("{n 1}") Sleep (100) Send("{f 1}") Sleep (100) Send("{l 1}") Sleep (100) Send("{i 1}") Sleep (100) Send("{c 1}") Sleep (100) Send("{t 1}") Sleep (100) Send("{s 1}") Sleep (100) Send("{o 1}") Sleep (100) Send("{u 1}") Sleep (100) Send("{l 1}") Sleep (100) Send("{Space 1}") Sleep (100) Send("{d 1}") Sleep (100) Send("{Enter 1}") Sleep (500) Send("{@ 1}") Sleep (100) Send("{c 1}") Sleep (100) Send("{o 1}") Sleep (100) Send("{n 1}") Sleep (100) Send("{f 1}") Sleep (100) Send("{l 1}") Sleep (100) Send("{i 1}") Sleep (100) Send("{c 1}") Sleep (100) Send("{t 1}") Sleep (100) Send("{s 1}") Sleep (100) Send("{o 1}") Sleep (100) Send("{u 1}") Sleep (100) Send("{l 1}") Sleep (100) Send("{Space 1}") Sleep (100) Send("{d 1}") Sleep (100) Send("{Enter 1}") Sleep (500) EndIf EndFunc While 1 Sleep(100) WEnd Link to comment Share on other sites More sharing options...
sdfaheemuddin Posted March 10, 2015 Share Posted March 10, 2015 use else statement instead of If not @error. Syntax for if else statement if condition then statements else statements endif Link to comment Share on other sites More sharing options...
JohnOne Posted March 10, 2015 Share Posted March 10, 2015 Should not make any difference in the above case. @error remains set from the result of PixelSearch until the script calls another function. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
travinia Posted March 10, 2015 Author Share Posted March 10, 2015 If anyone is able to edit the script and show me how it should be, would be a great help. Link to comment Share on other sites More sharing options...
SadBunny Posted March 10, 2015 Share Posted March 10, 2015 (edited) Change your script to this for debugging purposes: Global $Runner HotKeySet("{ESC}", "Terminate") HotKeySet("{F1}", "Click") Func Terminate() Exit 0 EndFunc ;==>Terminate Func Click() PixelSearch(1233, 826, 1386, 852, 0xFFCC00) If @error Then MsgBox(0,0,"@error was set!") EndIf If Not @error Then MsgBox(0,0,"@error was not set!") EndIf EndFunc ;==>Click While 1 Sleep(100) WEnd Much easier to read, and you'll see which part of the code is executed and which isn't. What sdfaheemuddin is saying is indeed a good idea. Even though your code should work as well, it is vulnerable to a situation where the @error is set or unset by any of the code in your first if-block, because the second if will read that new @error value that may not be the same since the first if. He is suggesting you avoid checking the @error again halfway your script, and go "IF <check @error: error was set> <do stuff> ELSE (meaning error was not set) <do other stuff>". This is both more efficient, because you won't have to perform a check twice, and safer. Global $Runner HotKeySet("{ESC}", "Terminate") HotKeySet("{F1}", "Click") Func Terminate() Exit 0 EndFunc ;==>Terminate Func Click() PixelSearch(1233, 826, 1386, 852, 0xFFCC00) If @error Then MsgBox(0, 0, "@error was set!") Else MsgBox(0, 0, "@error was not set!") EndIf EndFunc ;==>Click While 1 Sleep(100) WEnd Edited March 10, 2015 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
JohnOne Posted March 10, 2015 Share Posted March 10, 2015 Structure of your script is fine except you should return after calling functions in your If statements. Either way, one or both of the conditions will be met. HotKeySet("{ESC}", "Terminate") HotKeySet("{F1}", "Click") Func Terminate() Exit 0 EndFunc ;==>Terminate Func Click() _Func() If @error Then MsgBox(0,0, "Error") Return EndIf If Not @error Then MsgBox(0,0, "Not Error") Return EndIf EndFunc ;==>Click Func _Func() Local Static $error = 0 $error = Not $error Return SetError($error) EndFunc While 1 Sleep(100) WEnd AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted March 10, 2015 Share Posted March 10, 2015 SadBunny pipped me at the post there AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
travinia Posted March 10, 2015 Author Share Posted March 10, 2015 Thanks, but I also need the function to loop, and "While 1" doesnt seem to work in this situation. I have tried adding Do Send("{F1}") Sleep (3000) $i = $i + 1 Until $i = 1000 As a unreliable fix, but it also didnt work. expandcollapse popupHotKeySet("{ESC}", "Terminate") HotKeySet("{F1}", "Click") Global $Runner Func Terminate() Exit 0 EndFunc ;==>Terminate $i = 0 While 1 Sleep(100) WEnd Do Send("{F1}") Sleep (3000) $i = $i + 1 Until $i = 1000 Func Click() _Func() PixelSearch(1233, 826, 1386, 852, 0xFFCC00) If @error Then MouseClick("left", 716, 698, 10) Sleep (500) Send("{a down}") Sleep (800) Send("{a up}") Sleep (500) MouseClick("left", 716, 698, 10) Sleep (500) Send("{d down}") Sleep (800) Send("{d up}") Sleep (500) MouseClick("left", 716, 698, 10) Sleep (500) Return EndIf If Not @error Then Sleep (500) MouseClick("left", 863, 697, 3) Sleep (500) MouseClick("left", 701, 750, 3) Sleep (500) MouseClick("left", 863, 697, 3) Sleep (500) MouseClick("left", 701, 750, 3) Sleep (500) MouseClick("left", 1095, 873, 3) Send("{@ 1}") Sleep (100) Send("{c 1}") Sleep (100) Send("{o 1}") Sleep (100) Send("{n 1}") Sleep (100) Send("{f 1}") Sleep (100) Send("{l 1}") Sleep (100) Send("{i 1}") Sleep (100) Send("{c 1}") Sleep (100) Send("{t 1}") Sleep (100) Send("{s 1}") Sleep (100) Send("{o 1}") Sleep (100) Send("{u 1}") Sleep (100) Send("{l 1}") Sleep (100) Send("{Space 1}") Sleep (100) Send("{d 1}") Sleep (100) Send("{Enter 1}") Sleep (500) Send("{@ 1}") Sleep (100) Send("{c 1}") Sleep (100) Send("{o 1}") Sleep (100) Send("{n 1}") Sleep (100) Send("{f 1}") Sleep (100) Send("{l 1}") Sleep (100) Send("{i 1}") Sleep (100) Send("{c 1}") Sleep (100) Send("{t 1}") Sleep (100) Send("{s 1}") Sleep (100) Send("{o 1}") Sleep (100) Send("{u 1}") Sleep (100) Send("{l 1}") Sleep (100) Send("{Space 1}") Sleep (100) Send("{d 1}") Sleep (100) Send("{Enter 1}") Sleep (500) Send("{@ 1}") Sleep (100) Send("{c 1}") Sleep (100) Send("{o 1}") Sleep (100) Send("{n 1}") Sleep (100) Send("{f 1}") Sleep (100) Send("{l 1}") Sleep (100) Send("{i 1}") Sleep (100) Send("{c 1}") Sleep (100) Send("{t 1}") Sleep (100) Send("{s 1}") Sleep (100) Send("{o 1}") Sleep (100) Send("{u 1}") Sleep (100) Send("{l 1}") Sleep (100) Send("{Space 1}") Sleep (100) Send("{d 1}") Sleep (100) Send("{Enter 1}") Sleep (500) Return EndIf EndFunc ;==>Click Func _Func() Local Static $error = 0 $error = Not $error Return SetError($error) EndFunc Link to comment Share on other sites More sharing options...
JohnOne Posted March 10, 2015 Share Posted March 10, 2015 Been down this street many times, post your whole code. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
travinia Posted March 10, 2015 Author Share Posted March 10, 2015 (edited) I posted my whole code Edited March 10, 2015 by travinia Link to comment Share on other sites More sharing options...
markyrocks Posted March 10, 2015 Share Posted March 10, 2015 (edited) Here's your function loop... While 1 Function () Wend This will loop Function() forever. Ya a function won't execute unless it's called. Func to EndFunc just has what the function supposed to do. You call a function by simply typing it's name and (). Oic what you want. Just have your function call itself at the end... Or hotkeyset("{F1}","Loop") Func Loop () While 1 Click () Wend EndFunc Edited March 10, 2015 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 10, 2015 Moderators Share Posted March 10, 2015 travinia,Your basic request seems strangely similar to that of jamesch222 here - that plus other indications make me think that you are one and the same person. Multiple accounts are not permitted here so would you (or jamesch222) care to explain what is going on? 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 Link to comment Share on other sites More sharing options...
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