berkoma Posted March 3, 2014 Share Posted March 3, 2014 Hello, I'm totally new to AutoIT, though not new to coding per se, and I have a simple question that seems so basic that I can't really find an answer in any documentation (maybe it's not an imagesearch question at all, perhaps just a general AutoIT error). So I have this code that triggers a state when an image is found: ElseIf ( _ImageSearch("folder1/pics/state_7_btn.png",1, $_x, $_y,40) == 1) Then $state = $S_STATE7 What I've recently discovered is that depending on certain conditions, the state_7_btn.png can actually be different (its either blue and yellow, or a variant that is red and yellow). So now, I want to trigger the state $S_STATE7 when either the original, or the variant (lets call it state_7v_btn.png) is located. So, do I have to set separate states or is there a valid way to insert an "or" statement into this If statement? ie, ElseIf ( _ImageSearch("folder1/pics/state_7_btn.png",1, $_x, $_y,40) or ( _ImageSearch("folder1/pics/state_7v_btn.png",1, $_x, $_y,40) == 1) Then $state = $S_STATE7 I guess what I'm asking is what is the proper syntax to create an "If ImageA or ImageB then" statement Thanks in advance for any assistance Link to comment Share on other sites More sharing options...
Sori Posted March 3, 2014 Share Posted March 3, 2014 (edited) If _ImageSearch("folder1/pics/state_7_btn.png",1, $_x, $_y,40) == 1 or _ImageSearch("folder1/pics/state_7v_btn.png",1, $_x, $_y,40) == 1 Then $state = $S_STATE7 ;or If _ImageSearch("folder1/pics/state_7_btn.png",1, $_x, $_y,40) == 1 or _ _ImageSearch("folder1/pics/state_7v_btn.png",1, $_x, $_y,40) == 1 Then $state = $S_STATE7 ;underscore denotes continuing on the next line Edited March 3, 2014 by Sori If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects. Link to comment Share on other sites More sharing options...
berkoma Posted March 4, 2014 Author Share Posted March 4, 2014 If _ImageSearch("folder1/pics/state_7_btn.png",1, $_x, $_y,40) == 1 or _ImageSearch("folder1/pics/state_7v_btn.png",1, $_x, $_y,40) == 1 Then $state = $S_STATE7 ;or If _ImageSearch("folder1/pics/state_7_btn.png",1, $_x, $_y,40) == 1 or _ _ImageSearch("folder1/pics/state_7v_btn.png",1, $_x, $_y,40) == 1 Then $state = $S_STATE7 ;underscore denotes continuing on the next line When I try this I get "missing right bracket in expression" error. Link to comment Share on other sites More sharing options...
BrewManNH Posted March 4, 2014 Share Posted March 4, 2014 Just an aside, nothing to do with the question asked, but don't use "==" when comparing numbers as that should only be used for comparing strings with case sensitivity in AutoIt. It won't affect the scripts being posted, but unless you're made aware of this you might find your code doesn't do what you want it to because you're using the wrong operators. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
berkoma Posted March 4, 2014 Author Share Posted March 4, 2014 Just an aside, nothing to do with the question asked, but don't use "==" when comparing numbers as that should only be used for comparing strings with case sensitivity in AutoIt. It won't affect the scripts being posted, but unless you're made aware of this you might find your code doesn't do what you want it to because you're using the wrong operators. Thanks for the heads up, good to know. Seems to work when I use the code like this, does it look correct this way? If _ImageSearch("folder1/pics/state_7_btn.png",1, $_x, $_y,40) == 1) or _ImageSearch("folder1/pics/state_7v_btn.png",1, $_x, $_y,40) == 1) Then $state = $S_STATE7 Link to comment Share on other sites More sharing options...
AutID Posted March 4, 2014 Share Posted March 4, 2014 StringReplace($sString, "==", "=")as BrewManNH said https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
Solution berkoma Posted March 5, 2014 Author Solution Share Posted March 5, 2014 OK, well incorrect use of the '==' aside, seems that the way I have it now works, so I'll mark this as solved, thanks! Link to comment Share on other sites More sharing options...
AutID Posted March 5, 2014 Share Posted March 5, 2014 I am glad that you solved your problem but if you think that the code on post 5 is working as it is then I am sorry to disappoint you but it isn't. I didn't test it but just looking at it, well it is badly formatted. 1st if you want to chech if the image search returned true then use = 1 instead of == 1. Then remove the ) after the 1. I don't remember well the parameters of imagesearch... https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
berkoma Posted April 6, 2014 Author Share Posted April 6, 2014 I am glad that you solved your problem but if you think that the code on post 5 is working as it is then I am sorry to disappoint you but it isn't. I didn't test it but just looking at it, well it is badly formatted. 1st if you want to chech if the image search returned true then use = 1 instead of == 1. Then remove the ) after the 1. I don't remember well the parameters of imagesearch... Well, i've updated my method now to use imagesearcharea instead, but prior to that, this script ran as posted for nearly a month, 24/7 without problems, so badly formatted it may be, but to claim its "not working" is simply untrue, lol. Link to comment Share on other sites More sharing options...
AutID Posted April 7, 2014 Share Posted April 7, 2014 It will work but it is not correct. Double == will check if the return of the function, which is 1 turned into a string, = String("1"), not if it is true. Since the function returns 1 which means true it will work. However if you want to check if it returned true it is better to use: If _MyFunc() = 1 or If _MyFunc() = True Double equals are used for string. So basically you are comparing a string with a string not a function with the return. If your function will return a value instead of true then you will have problems using your way to check if it returned true. https://iblockify.wordpress.com/ 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