LordTakahiro Posted July 14, 2016 Share Posted July 14, 2016 Hey guys, I need some help with this code I'm working on. For some reason my MouseClick at the end of my function gets called multiple times and I can't seem to figure out why that's happening. $finallyOver = False Func testFunc() isOver() If $finallyOver = False Then $var = PixelSearch(334,255,633,681,0x228ADD) If IsArray($var) = True Then MouseClick("left",$var[0],$var[1], 1, 10) Sleep(1500) MouseClick("left",$var[0],$var[1], 1, 10) EndIf Sleep(500) testFunc() EndIf Sleep(1000) ConsoleWrite("Clicked Here ") MouseClick("left",492,730) Sleep(2000) EndFunc Func isOver() $result = PixelSearch(423,714,541,742,0x999999) If IsArray($result) = True Then $finallyOver = True EndIf EndFunc Any help would be greatly appreciated. I'm pretty new to Autoit (and these forums) so I still don't know how everything works. Been working with Autoit for maybe 3-4 days now. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 14, 2016 Moderators Share Posted July 14, 2016 @LordTakahiro you will find as you venture further into AutoIt coding that PixelSearch and MouseClick can both be unstable. More often than not, there is a much better way to accomplish what you are after. How about a detailed description of what application you're working in and what you are trying to accomplish with your mouse clicks, so we can better assist you? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
LordTakahiro Posted July 14, 2016 Author Share Posted July 14, 2016 I don't know how much I can talk about because this is mainly for work and I don't want to break any NDA's. I'm working on creating something that can help me with testing monotonous things at work like selecting rewards cards. Basically what this is doing is first checking if we are done selecting cards, if not then it goes to selecting a card based on a pixel on the card until the initial condition is met, then it clicks on the proceed button then it should be done. The problem I'm having is that once the program finds the "proceed" button, it clicks that location multiple times instead of just once. What I'm thinking is that it's because of the recursion I have in the code to recall itself, but I'm not exactly sure how Autoit works so I can't be completely sure about that. Link to comment Share on other sites More sharing options...
LordTakahiro Posted July 15, 2016 Author Share Posted July 15, 2016 So is no one able to help with this? I understand if not. (Sorry to bump) Link to comment Share on other sites More sharing options...
SadBunny Posted July 15, 2016 Share Posted July 15, 2016 With this information there's not a whole lot more anyone could do than speculate. Please write a reproducer that shows your problem or explain more about what you're automating (preferably both ). Writing a reproducer that works on a test gui instead of the real thing is probably going to show where the problem is. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
LordTakahiro Posted July 15, 2016 Author Share Posted July 15, 2016 Still new to Autoit so I don't really know what a reproducer is to be honest.... BUT! I can explain more about this. Basically the first thing it's doing is checking to see if a button has popped up to say "Proceed" meaning that there are no more picks you can use to pick cards. If the button is not up, it is supposed to click on a card, wait a second, and click on it again to take it off it's pop up, and that's if it's able to find a card (Which it normally is able to). Since it was not able to find the proceed button and chose a card instead, it does some recursion and recalls itself to start the function over. There I believe in lies the problem. Like I stated, I'm not too familiar with Autoit so I don't know exactly how execution works. What I am assuming is that the program initially starts, doesn't finish the function, calls itself, doesn't finish the function, calls itself, etc until the button shows. Then I THINK, I'm not sure, that it finished each one of those functions and clicks the mouse once for each time that the function was called. Thank you for any help in this matter. Link to comment Share on other sites More sharing options...
SadBunny Posted July 15, 2016 Share Posted July 15, 2016 Well, AutoIt doesn't have an infinite recursion capacity or something, after a few hundred iterations there's gonna be a stack overflow. So that's one thing. In your script, there's no reason at all to use recursion (why use up the stack if you don't have to?). Why not just use a while loop? LordTakahiro 1 Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
LordTakahiro Posted July 16, 2016 Author Share Posted July 16, 2016 9 hours ago, SadBunny said: Well, AutoIt doesn't have an infinite recursion capacity or something, after a few hundred iterations there's gonna be a stack overflow. So that's one thing. In your script, there's no reason at all to use recursion (why use up the stack if you don't have to?). Why not just use a while loop? You are completely correct. Thank you so much for pointing that out to me. I changed the recursion to a while loop and everything works as planned. Thank you for the help. Don't know why I didn't think of doing that sooner. Link to comment Share on other sites More sharing options...
SadBunny Posted July 16, 2016 Share Posted July 16, 2016 You're welcome Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
SadBunny Posted July 16, 2016 Share Posted July 16, 2016 Could it be that you are coming from... another language... that maybe uses GOTO statements? Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
LordTakahiro Posted July 16, 2016 Author Share Posted July 16, 2016 Problem is I've been trying to learn so many new languages recently that my mind is being jumbled with different syntax's lol. 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