Jump to content


Photo

Help required with 'if' statement please...


  • Please log in to reply
2 replies to this topic

#1 Pilkojr

Pilkojr
  • Members
  • 29 posts

Posted 10 April 2012 - 05:00 AM

#.::
Loop
{
CoordMode Pixel, Relative ; Interprets the coordinates below as relative to the screen rather than the active window.
ImageSearch, FoundX, FoundY, 10,65, 1356, 743, *8 C:\Users\Pilkojr\Documents\bweast1.png
if ErrorLevel = 2
{
    MsgBox Could not conduct the search.
    break
}
MouseMove, FoundX+3, FoundY+3
; Click
Sleep 200
}
Return

The above code is finding the image fine on the screen then moving the mouse to the required location, but it is also clicking whenever the image isn't found onscreen.
I'm trying to get the mouse to click on the found image only when the image is onscreen.
How would I insert an IF statement that would only click if and when the image is found?

Ta Pilkojr

#2 Blackholyman

Blackholyman
  • Members
  • 1209 posts

Posted 10 April 2012 - 05:15 AM

try this :)

#.::
Loop
{
CoordMode Pixel, Relative ; Interprets the coordinates below as relative to the screen rather than the active window.
ImageSearch, FoundX, FoundY, 10,65, 1356, 743, *8 C:\Users\Pilkojr\Documents\bweast1.png
if ErrorLevel = 2
{
    MsgBox Could not conduct the search.
    break
}
[color=#FF0000]else if ErrorLevel = 0[/color]
{
MouseMove, FoundX+3, FoundY+3
Click
Sleep, 200
Break
}
Return

hope it helps

#3 Pilkojr

Pilkojr
  • Members
  • 29 posts

Posted 10 April 2012 - 01:47 PM

Thank you Blackholyman. That helped heaps and did the trick. I just had to increase the 'Sleep' value to a few seconds to get it to work correctly.