Jump to content

I need help with a loop


Recommended Posts

While 1
    $a = PixelGetColor(835,302) 
    $b = PixelGetColor(840,435)
    If $a = 0x5383E8 Then
    MouseClick("Left",835,302,1)
    Elseif $b = 0x818AA0
    ExitLoop
    EndIf
    WEnd

What I'm trying to do is wait for $a to become a color and then left click (takes about 40 seconds usually). Problem is that $a doesn't always change to the color I want so I want to look for either $a = 0x5383E8 or $b = 0x818AA0 (which happens if $a doesn't show up). What I am getting with the above code is that the loop exits immediatly instead of looping until either $a or $b = the color I need it to. How do I loop this so that it keeps looking until either happens?

Link to comment
Share on other sites

Try this:

While 1
    $a = PixelGetColor(835, 302)
    $b = PixelGetColor(840, 435)
    If $a = 0x5383E8 Or $b = 0x818AA0 Then
        MouseClick("Left", 835, 302, 1)
        ;Exit ;Uncomment this if you want to exit after the left mouse click ;)
    EndIf
WEnd

BTW be carefull of what are you doing ;)

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

PixelGetColor returns a decimal representation of a color. If you wish to compare it to a hex color, specify the output as Hex. Also use quotations for the values.

Also in your code, the loop never ends if $a is found.

While 1
  $a = Hex(PixelGetColor(835,302), 6)
  $b = Hex(PixelGetColor(840,435), 6)
  If $a = "5383E8" Then
    MouseClick("Left",835,302,1)
    ConsoleWrite("$a was found" & @CRLF)
  Elseif $b = "818AA0" Then
    ConsoleWrite("$b was found" & @CRLF)
    ExitLoop
  Else
    ConsoleWrite("Neither value found, continue loop" & @CRLF)
  EndIf
WEnd
Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

PixelGetColor returns a decimal representation of a color. If you wish to compare it to a hex color, specify the output as Hex. Also use quotations for the values.

You can directly compare a hex value with a decimal value in AutoIt, no need to convert it from one to the other.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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