Sc1 Posted June 24, 2008 Share Posted June 24, 2008 I have been trying to use a Do...Until loop to get AutoIt to search the area around the cursor for a specific colour, then when that colour is found finish the loop. The script itself runs fine, having not come up with any errors. However it never finds the colour I want it to look for, even when I made the rectangle the size of my screen. I've also rechecked the colour several times and put variation to max but still nothing. Could someone please explain why the script doesn't ever fulfil the Until command? Thank you in advance. CODEDo $pos = MouseGetPos() $colour = PixelSearch($pos[0],$pos[1],$pos[0] + 10,$pos[1] + 10,"245DDB",50) Until $colour = $pos MsgBox(0,"Colour","Colour found at: " & $colour[0] & $colour[1]) Link to comment Share on other sites More sharing options...
Valuater Posted June 24, 2008 Share Posted June 24, 2008 (edited) MouseGetPos() and PixelSearch() both return arrays so.This can not workUntil $colour = $posDo Sleep(5) ; slow CPU usage $pos = MouseGetPos() $colour = PixelSearch($pos[0],$pos[1],$pos[0] + 10,$pos[1] + 10,"245DDB",50) Until $colour[0] = $pos[0] MsgBox(0,"Colour","Colour found at: " & $colour[0] & $colour[1])oÝ÷ ØC¶²ËbYèµÊ+ç-mçºÇç(æk&Þ~§wítk²~º&¶¦¢ë¦"¶*'z÷§mëmz¶®¶sdFð 6ÆVWR²6Æ÷r5RW6vP¢b33c·÷2ÒÖ÷W6TvWE÷2¢b33c¶6öÆ÷W"ÒVÅ6V&6b33c·÷5³ÒÂb33c·÷5³ÒÂb33c·÷5³Ò²Âb33c·÷5³Ò²ÂgV÷C³#CTDD"gV÷C²ÃS¥VçFÂ4'&b33c¶6öÆ÷W"¤×6t&÷ÂgV÷C´6öÆ÷W"gV÷C²ÂgV÷C´6öÆ÷W"f÷VæBC¢gV÷C²fײb33c¶6öÆ÷W%³Òfײb33c¶6öÆ÷W%³Ò8)8) Edited June 24, 2008 by Valuater Link to comment Share on other sites More sharing options...
Sc1 Posted June 24, 2008 Author Share Posted June 24, 2008 I added in the $colour[0] = $pos[0] and it read up until there and then errored with: Subscript used with non-Array variable.: Until $colour[0] = $pos[0] Until $colour^ ERROR Link to comment Share on other sites More sharing options...
Valuater Posted June 24, 2008 Share Posted June 24, 2008 see my second script 8) Link to comment Share on other sites More sharing options...
Sc1 Posted June 24, 2008 Author Share Posted June 24, 2008 Thanks, it comes up now, but it takes a long time to find the colour. I changed the colour to white, and placed the cursor on a blank white page and it took 20 seconds to find the colour. Is there any reson for this or is PixelSearch just a slow command? Link to comment Share on other sites More sharing options...
ofLight Posted June 24, 2008 Share Posted June 24, 2008 I tried your script looking for Black, and its pretty much instantaneous. you also only had it looking to the Right and Below the cursor by 10 pixels. Do Sleep(5) ; slow CPU usage $pos = MouseGetPos() $colour = PixelSearch($pos[0]-10,$pos[1]-10,$pos[0] + 10,$pos[1] + 10,0,50) Until IsArray($colour) MsgBox(0,"Colour","Colour found at X:"&$colour[0]&" Y:"&$colour[1]) There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly Link to comment Share on other sites More sharing options...
Sc1 Posted June 24, 2008 Author Share Posted June 24, 2008 Odd... I'll try it again looking above the cursor when I get home and have access to AutoIt. Thanks for the help so far. Link to comment Share on other sites More sharing options...
aslani Posted June 24, 2008 Share Posted June 24, 2008 Thanks, it comes up now, but it takes a long time to find the colour. I changed the colour to white, and placed the cursor on a blank white page and it took 20 seconds to find the colour. Is there any reson for this or is PixelSearch just a slow command? For some reason, defining the color to search as "FFFFFF" for white returns an error after a lengthy search. After testing it, PixelSearch() do not like "FFFFFF", but it accepts 0xFFFFFF just fine (without the quotes) Do Sleep(5) ; slow CPU usage $pos = MouseGetPos() $colour = PixelSearch($pos[0], $pos[1], $pos[0] + 3, $pos[1] + 3, 0xFFFFFF, 125) Until IsArray($colour)oÝ÷ Ùh^ÚØb²Ç+ZºÚ"µÍÌÍÜÜÈH[ÝÙQÙ]ÜÊ BÌÍÙÛÛÜH^[Ù]ÛÛÜ ÌÍÜÜÖÌK ÌÍÜÜÖÌWJBÂÛY JHÈÛÝÈÔHØYÙBÌÍØÛÛÝH^[ÙXÚ ÌÍÜÜÖÌK ÌÍÜÜÖÌWK ÌÍÜÜÖÌH ÈË ÌÍÜÜÖÌWH ÈËB[[Ð^J ÌÍØÛÛÝHÔ ÌÍØÛÛÝHHÈYY ][ÝÓÔÜÈÛÛÜÈÝÝ[Y ÌÍØÛÛÝHH[SÙÐÞ ][ÝÑZ[Y ÌÌÎÉ][ÝË ][ÝÐÛÛÜH ][ÝÈ [È^ ÌÍÙÛÛÜ H [ÈÔ [È ][ÝÓ[ÝÙHÜÈH ][ÝÈ [È ÌÍÜÜÖÌH [È ][ÝË ][ÝÉ[È ÌÍÜÜÖÌWH [È ][ÝÊI][ÝÈ [ÈÔ [È ][ÝÐÛÛÜÝÝ[][ÝÊB[ÙBSÙÐÞ ][ÝÐÛÛÝ][ÝË ][ÝÐÛÛÜH ][ÝÈ [È^ ÌÍÙÛÛÜ H [ÈÔ [È ][ÝÓ[ÝÙHÜÈH ][ÝÈ [È ÌÍÜÜÖÌH [È ][ÝË ][ÝÉ[È ÌÍÜÜÖÌWH [È ][ÝÊI][ÝÈ [ÈÔ [È ][ÝÐÛÛÝÝ[]][ÝÉ[ÉÌÍØÛÛÝÌI[É][ÝÈN][ÝÉ[ÉÌÍØÛÛÝÌWJB[Y I found that the reason why it takes too long is because of the "Until IsArray($colour)" which will keep on looping even if the color was not found. After adding "OR $colour = 1", the loop terminate as intended almost instantly. [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 24, 2008 Moderators Share Posted June 24, 2008 Thanks, it comes up now, but it takes a long time to find the colour. I changed the colour to white, and placed the cursor on a blank white page and it took 20 seconds to find the colour. Is there any reson for this or is PixelSearch just a slow command?If aslani's suggestion does not work for speed... are you using Vista? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Sc1 Posted June 25, 2008 Author Share Posted June 25, 2008 Lol, not using Vista. Just got home so will try it again now. Link to comment Share on other sites More sharing options...
Sc1 Posted June 25, 2008 Author Share Posted June 25, 2008 Okay, it works fine, however if it does not find the colour i'm looking for (245DDB) I would like it to loop back until it does find this colour. I have encased it in a While loop and it's not erroring however i've now got the same problem I originally had of nothing happening. CODE#include <Misc.au3> #include <Array.au3> While 1 $pos = MouseGetPos() $fColor = PixelGetColor($pos[0],$pos[1]) Do Sleep(5) ; slow CPU usage $colour = PixelSearch($pos[0], $pos[1], $pos[0] + 3, $pos[1] + 3, 0x245DDB) Until IsArray($colour) OR $colour = 1 ; Added "OR @error is color is not found. WEnd Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 25, 2008 Moderators Share Posted June 25, 2008 Okay, it works fine, however if it does not find the colour i'm looking for (245DDB) I would like it to loop back until it does find this colour. I have encased it in a While loop and it's not erroring however i've now got the same problem I originally had of nothing happening. CODE#include <Misc.au3> #include <Array.au3> While 1 $pos = MouseGetPos() $fColor = PixelGetColor($pos[0],$pos[1]) Do Sleep(5) ; slow CPU usage $colour = PixelSearch($pos[0], $pos[1], $pos[0] + 3, $pos[1] + 3, 0x245DDB) Until IsArray($colour) OR $colour = 1 ; Added "OR @error is color is not found. WEndUmm... You're just looping forever... without telling it to do something if the color is found... While 1 $pos = MouseGetPos() $fColor = PixelGetColor($pos[0],$pos[1]) Do Sleep(5); slow CPU usage $colour = PixelSearch($pos[0], $pos[1], $pos[0] + 3, $pos[1] + 3, 0x245DDB) Until IsArray($colour) OR $colour = 1; Added "OR @error is color is not found. ;;;; Tell it to do something here WEnd Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 25, 2008 Share Posted June 25, 2008 (edited) SmOke_N probably already knows this but the rest of you should know that if you use Sleep() with values above 0 then the minimum (doesn't matter what you wrote) is 10. So if you write Sleep(5) it will be double as long as you specify (since 5 is half of 10). Edit: Easily proven like this: $begin = TimerInit() Sleep(0) MsgBox(0, "", TimerDiff($begin)) $begin = TimerInit() Sleep(1) MsgBox(0, "", TimerDiff($begin)) $begin = TimerInit() Sleep(10) MsgBox(0, "", TimerDiff($begin)) Edited June 25, 2008 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 25, 2008 Moderators Share Posted June 25, 2008 SmOke_N probably already knows this but the rest of you should know that if you use Sleep() with values above 0 then the minimum (doesn't matter what you wrote) is 10. So if you write Sleep(5) it will be double as long as you specify (since 5 is half of 10). Edit: Easily proven like this: $begin = TimerInit() Sleep(0) MsgBox(0, "", TimerDiff($begin)) $begin = TimerInit() Sleep(1) MsgBox(0, "", TimerDiff($begin)) $begin = TimerInit() Sleep(10) MsgBox(0, "", TimerDiff($begin))Yes, never bothered to look at the sleep, 1 to 9 is the same as 10... We've said this to many others over the years. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Sc1 Posted June 25, 2008 Author Share Posted June 25, 2008 Kay, thanks very much guys. It seems to be working great now. Thank you for your help. 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