Sign in to follow this  
Followers 0
Sc1

Do Until and PixelSearch problem

15 posts in this topic

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.

CODE
Do

$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])

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

MouseGetPos() and PixelSearch() both return arrays so.

This can not work

Until $colour = $pos

Do
    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 by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

see my second script

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Lol, not using Vista. Just got home so will try it again now.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Umm... 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.

Share this post


Link to post
Share on other sites

#13 ·  Posted (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 by AdmiralAlkex

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Kay, thanks very much guys. It seems to be working great now. Thank you for your help. :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0