sweyko5 Posted April 3, 2010 Share Posted April 3, 2010 Hi I'm trying to work with a while statement and I can't seem to figure out what the problem is. I'll Show you the code and then explain what the problem is after: $vartemp = 0 While $vartemp < 2 $var2 = PixelSearch( 700,183,701,184,0xCA2121,10,1 ) While $var2[1] = 183 mouseclick("left",780,319,2,2) sleep(200) $var2 = PixelSearch( 700,183,701,184,0xCA2121,10,1 ) WEnd mouseclick("left",762,258,2,2) sleep(300) mouseclick("left",803,284,2,2) sleep(300) mouseclick("left",780,319,2,2) sleep(5000) mouseclick("left",1094,332,3) $vartemp = $vartemp + 1 WEnd Ok so basically what im trying to do with this code is when there is a certain color pixel at the coordinates specified I want it to keep clicking in a certain place, after the color goes away it needs to click in 4 different places and then i want the whole process to restart. So when i execute this it checks for the pixels and it starts clicking where i want it, then when the color changes instead of it moving on to the next 4 clicks it just stops completely. so after the while statement that checks for the pixels is false it wont move onto the next part of the code. The only reason i can think this is even doing this is because when the pixel search comes back false then $var2[1] becomes nothing, but then i don't understand why it wont just move on because $var2[1] wouldnt equal 183. I'm not too sure on this and any help is greatly appreciated. Thanks, Sweyko5 Link to comment Share on other sites More sharing options...
ericnail Posted April 3, 2010 Share Posted April 3, 2010 (edited) #include <Array.au3> Dim $var2[6] ;Set the deminsions of $var2's Arrays While 1 ;Do Always _CheckColor() ;Check pixels' current color If $var2[1] = 183 Then ;If this, Click every 0.2 seconds and check if the pixel has changed Do mouseclick("left",780,319,2,2) sleep(200) _CheckColor() Until $var2[1] <> 183 ;When the Pixel changes, Follow the Restart Function and wait for IF statement to be true _Restart() Else _CheckColor() ;If the statement is not true, then keep checking until it is EndIf WEnd Func _Restart() ;Click 4 places and resume 'While 1' mouseclick("left",762,258,2,2) sleep(300) mouseclick("left",803,284,2,2) sleep(300) mouseclick("left",780,319,2,2) sleep(5000) mouseclick("left",1094,332,3) EndFunc Func _CheckColor() ;Return the current color of the pixel Return $var2 = PixelSearch( 700,183,701,184,0xCA2121,10,1 ) EndFuncTry thisThis Expression:$vartemp = $vartemp + 1Is located inside the first While loop, therefore the loop doesn't include that expression while testing the statement.Also, you failed to set the dimensions of the Arrays you were using, on top of not including the "Array.au3" file. Edited April 3, 2010 by ericnail Link to comment Share on other sites More sharing options...
sweyko5 Posted April 3, 2010 Author Share Posted April 3, 2010 (edited) Thanks for the reply ericnail but when I tried using that it wouldn't do the first click (the one every .2 seconds) when the color was defiantly there. And i must say the code you posted confuses me so If it's something little with your code i wouldn't be able to figure it outAlso I don't know if this effects anything but i do have like 50 lines of code before i have this While statementAgain thanks for attempting to help.Edit: Ok im going to start off saying I'm not in anyway very good at programming languages but i do have a decent amount of experience,About you saying that the while statement wont include that expression while testing the statement is true but i have $vartemp = 0 before the loop starts so the first time it will be less than 2, then it will run all the code, eventually adding 1 to $vartemp making it equal to one, then it should re-test the expresion and $vartemp would still be less than 2but that really doesnt seem like the problem to me because it wont even do those 4 clicks the first which doesnt make sense to meIf i am wrong please correct me Edited April 3, 2010 by sweyko5 Link to comment Share on other sites More sharing options...
ericnail Posted April 3, 2010 Share Posted April 3, 2010 (edited) Thanks for the reply ericnail but when I tried using that it wouldn't do the first click (the one every .2 seconds) when the color was defiantly there. And i must say the code you posted confuses me so If it's something little with your code i wouldn't be able to figure it out Also I don't know if this effects anything but i do have like 50 lines of code before i have this While statement Again thanks for attempting to help. Call me Eric I definitely need to see the rest of the code to help you out. Also, What are you using this on? It's hard to code in the dark. Ok im going to start off saying I'm not in anyway very good at programming languages but i do have a decent amount of experience, About you saying that the while statement wont include that expression while testing the statement is true but i have $vartemp = 0 before the loop starts so the first time it will be less than 2, then it will run all the code, eventually adding 1 to $vartemp making it equal to one, then it should re-test the expresion and $vartemp would still be less than 2 Well, It wont ever check the statement again because when you end the while statement, It might be equil to one, however it then is told that it's = to 0 again, therefore making it a moot point. Also, If you're looking to add by one, the proper statement would be: $Variable +=1 However, that was just a useless command, really had nothing to do with your current problem. Edited April 3, 2010 by ericnail Link to comment Share on other sites More sharing options...
sweyko5 Posted April 3, 2010 Author Share Posted April 3, 2010 Call me Eric I definitely need to see the rest of the code to help you out. Also, What are you using this on? It's hard to code in the dark. Well, It wont ever check the statement again because when you end the while statement, It might be equil to one, however it then is told that it's = to 0 again, therefore making it a moot point. Also, If you're looking to add by one, the proper statement would be: $Variable +=1 However, that was just a useless command, really had nothing to do with your current problem. Hmm alright Eric, If you really want to help me out I can send you the source code via E-Mail or AIM if you have it. Send me a PM either way and we chat about it a little more, and i really appreciate the help this is the first time i have been completely stumped by autoit Link to comment Share on other sites More sharing options...
ericnail Posted April 3, 2010 Share Posted April 3, 2010 Hmm alright Eric, If you really want to help me out I can send you the source code via E-Mail or AIM if you have it. Send me a PM either way and we chat about it a little more, and i really appreciate the help this is the first time i have been completely stumped by autoitI take it it's private?Okay, well send me a message on the boards with the script and what you're using it for and I'll see what I can do. Link to comment Share on other sites More sharing options...
sweyko5 Posted April 3, 2010 Author Share Posted April 3, 2010 I take it it's private?Okay, well send me a message on the boards with the script and what you're using it for and I'll see what I can do.Ok i sent you a PM, thanks. Link to comment Share on other sites More sharing options...
ericnail Posted April 3, 2010 Share Posted April 3, 2010 expandcollapse popupWhile 1 AdlibRegister("_CheckColor", 100) ;Check The Color of the Pixel 10x/Second (Every 1/10 Second) _CheckTime() If $Go = True Then ;Check If the pixel is the right color If $Restart = True Then ;Check if the second attack has already occured _AttackOne() EndIf ElseIf $Go = True Then ;This clause shouldn't be activated and is here as only a failsafe If $Restart = False Then _AttackTwo() EndIf EndIf WEnd Func _AttackOne() Do mouseclick("left",788,255,2,2) ;click attack 1 sleep(300) ; mouseclick("left",762,258,2,2) ;click attack 2 sleep(300) ; mouseclick("left",755,240,2,2) ;click attack 3 sleep(300) ; mouseclick("left",803,284,2,2) ;click attack 4 sleep(300) ; mouseclick("left",780,319,2,2) ;click attack 5 sleep(200) Until $Go = False Sleep(5000) _AttackTwo() EndFunc Func _AttackTwo() $timer = TimerInit() mouseclick("left",762,258,2,2) ;click attack 2 sleep(300) ; mouseclick("left",755,240,2,2) ;click attack 3 sleep(300) ; mouseclick("left",803,284,2,2) ;click attack 4 sleep(300) ; mouseclick("left",780,319,2,2) ;click attack 5 sleep(5000) ; mouseclick("left",1094,332,3) ; $Difference = TimerDiff($timer) EndFunc Func _CheckColor() ;Return the current color of the pixel $PixelColor = PixelGetColor(0, 0); Enter the X & Y Coords of the pixel you want to moniter If $PixelColor = 0xCA2121 Then $Go = True ElseIf $PixelColor <> 0xCA2121 Then $Go = False EndIf EndFunc Func _CheckTime() Switch $Difference Case $Difference < 100 ;If _AttackTwo() Has yet to be run, then Don't Restart $Restart = False Case $Difference >= 100 ;If _AttackTwo() Has been run, then Restart $Restart = True $Difference = 0 EndSwitch EndFunc Try this one Link to comment Share on other sites More sharing options...
sweyko5 Posted April 3, 2010 Author Share Posted April 3, 2010 expandcollapse popupWhile 1 AdlibRegister("_CheckColor", 100) ;Check The Color of the Pixel 10x/Second (Every 1/10 Second) _CheckTime() If $Go = True Then ;Check If the pixel is the right color If $Restart = True Then ;Check if the second attack has already occured _AttackOne() EndIf ElseIf $Go = True Then ;This clause shouldn't be activated and is here as only a failsafe If $Restart = False Then _AttackTwo() EndIf EndIf WEnd Func _AttackOne() Do mouseclick("left",788,255,2,2) ;click attack 1 sleep(300) ; mouseclick("left",762,258,2,2) ;click attack 2 sleep(300) ; mouseclick("left",755,240,2,2) ;click attack 3 sleep(300) ; mouseclick("left",803,284,2,2) ;click attack 4 sleep(300) ; mouseclick("left",780,319,2,2) ;click attack 5 sleep(200) Until $Go = False Sleep(5000) _AttackTwo() EndFunc Func _AttackTwo() $timer = TimerInit() mouseclick("left",762,258,2,2) ;click attack 2 sleep(300) ; mouseclick("left",755,240,2,2) ;click attack 3 sleep(300) ; mouseclick("left",803,284,2,2) ;click attack 4 sleep(300) ; mouseclick("left",780,319,2,2) ;click attack 5 sleep(5000) ; mouseclick("left",1094,332,3) ; $Difference = TimerDiff($timer) EndFunc Func _CheckColor() ;Return the current color of the pixel $PixelColor = PixelGetColor(0, 0); Enter the X & Y Coords of the pixel you want to moniter If $PixelColor = 0xCA2121 Then $Go = True ElseIf $PixelColor <> 0xCA2121 Then $Go = False EndIf EndFunc Func _CheckTime() Switch $Difference Case $Difference < 100 ;If _AttackTwo() Has yet to be run, then Don't Restart $Restart = False Case $Difference >= 100 ;If _AttackTwo() Has been run, then Restart $Restart = True $Difference = 0 EndSwitch EndFunc Try this one Err idk man i've been trying to work with that for the last couple hours, but no matter how much i would adjust it wouldnt even do the first attacks im so confused lol Link to comment Share on other sites More sharing options...
ericnail Posted April 7, 2010 Share Posted April 7, 2010 Err idk man i've been trying to work with that for the last couple hours, but no matter how much i would adjust it wouldnt even do the first attacks im so confused lol Problem Solved Solution: expandcollapse popup$var2 = 0 Func _AttackOne() mouseclick("left",788,255,2,2) ;click attack 1 sleep(300) ; mouseclick("left",762,258,2,2) ;click attack 2 sleep(300) ; mouseclick("left",755,240,2,2) ;click attack 3 sleep(300) ; mouseclick("left",803,284,2,2) ;click attack 4 sleep(300) ; mouseclick("left",780,319,2,2) ;click attack 5 sleep(200) EndFunc Func _AttackTwo() mouseclick("left",762,258,2,2) ;click attack 2 sleep(300) ; mouseclick("left",755,240,2,2) ;click attack 3 sleep(300) ; mouseclick("left",803,284,2,2) ;click attack 4 sleep(300) ; mouseclick("left",780,319,2,2) ;click attack 5 EndFunc $blah = False sleep(1250) MouseClick("left",167,882,1,0) ;CENSORED sleep(2350) mouseclick("left",1094,332,3) ;CENSORED sleep(790) while $var2 < 30 sleep(200) $var = PixelGetColor(700,184) if $var = 12852766 Then $Go = True ElseIf $var <> 12852766 Then $Go = False EndIf sleep(200) Do _AttackOne() sleep(200) $var = PixelGetColor(700,184) if $var = 12852766 Then $blah = True ElseIf $var <> 12852766 Then $blah= False EndIf Until $blah = False _AttackTwo() sleep(1000) _AttackTwo() $var2 += 1 $var3 = PixelGetColor(413,208) if $var3 = 16755370 Then $pause = 161666 ElseIf $var3 <> 16755370 Then $pause = 29666 EndIf MouseClick("left",387,886,1,3) sleep(666) MouseClick("left",265,94,1,3) sleep(666) Send("{ENTER}") sleep(666) Send("{ENTER}") sleep(666) $time = @hour & ":" & @MIN & ":" & @SEC Send( $time & ": " & $var2 & " CENSORED") sleep($pause) mouseclick("left",1094,332,3) ; WEnd 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