Jump to content

While Loop help


ttleser
 Share

Recommended Posts

I want to create a simple program that will:

1. Hold the script until a certain color is at a certain pixel location and move the mouse and click at a certain location.

2. Then I want it to wait until a another window appears with "Blizzard Updater" in the title and "The update was successful." in the text.

I was able to get #1 working, but not continually wait until the color at that pixel location is "FFC700".

The problem with #2 is that a window that's titled "1% - Blizzard Updater" will appear and will download the update and the percentage in the window title will continually change until it says 100%. I need the second part of the script to be able to wait until it shows "100% - Blizzard Updater" then continue with the script.

Here's what I've got so far, thoughts?

$var = PixelGetColor( 622, 301)
$var1 = Hex($var,6)
While $var1 <> "FFC700"
    sleep(1000)
    MouseClick("left", 520, 443, 1)
WEnd
Opt("WinTitleMatchMode", 2)

While 1
    $var2 = WinExists("Blizzard Updater", "The update was successful.")
    If $var2 = 1 Then
        send("{ENTER}")
        sleep(10000)
        send("{ALTDOWN}{F4}{ALTUP}")
        Exitloop
    EndIf
WEnd
Link to comment
Share on other sites

One of the problems is that you're not checking the color more than once at the beginning. Try something like...

Do
    $var = PixelGetColor(622, 301)
    $var1 = Hex($var, 6)
    Sleep(100)
Until $var1 <> 'FFC700'

MouseClick("left", 520, 443, 1)

If you want to wait until it says "100% - Blizzard Updater" maybe that should be in the title or text? Try to make sure you're using the right wintitlematch mode, and your title/text is what it should be. Also, the text is optional.

Link to comment
Share on other sites

Thanks Xcal. The Do loop for the first part, I missed that one. :)

For the second loop, the 100% will only show up when it's done downloading. Is my loop setup right for that if I just change it to:

While 1
    If WinExists("100% - Blizzard Updater", "The update was successful.") Then
        Send("{ENTER}")
        Sleep(10000)
        Send("{ALTDOWN}{F4}{ALTUP}")
        ExitLoop
    EndIf
    Sleep(100)
WEnd
Link to comment
Share on other sites

Also, since Send acts on the active window and you're only checking if the window exists, it's not

exactly very safe. Consider replacing WinExists with WinActive and/or Send with ControlSend.

Btw, since nothing is done in your second loop before the window exists, you can just use WinWait

instead...

EDIT : Last note... to close the window you can just use Send("!{F4}") or even WinClose.

Edited by Helge
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...