AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Separate commands from the loop

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
whocares



Joined: 15 Jul 2007
Posts: 6

PostPosted: Mon Jul 16, 2007 4:31 am    Post subject: Separate commands from the loop Reply with quote

wantedColor = 0xFFFFFF
crossX = 40
crossY = 78
Loop
{
PixelGetColor, notepadColor, %crossX%, %crossY%
if %ErrorLevel% = 0
Sendplay hello
sleep 200
}


This is a script I found that will send "hello" repeatedly whenever a pixel at the specified coordinates are the correct color. I'd like the script to work so that once the correct color is detected the script sends "hello" only once, instead of looping it.
Back to top
View user's profile Send private message
mwharri



Joined: 15 Mar 2007
Posts: 70

PostPosted: Mon Jul 16, 2007 7:24 am    Post subject: Reply with quote

Code:

wantedColor = 0xFFFFFF
crossX = 40
crossY = 78
Loop
{
PixelGetColor, notepadColor, %crossX%, %crossY%
if %ErrorLevel% = 0
Sendplay hello
sleep 200
}


I think this should work...untested

Code:

msgSentOnce = 0
wantedColor = 0xFFFFFF
crossX = 40
crossY = 78
SetTimer, isColorThere, 1000

isColorThere:
    if msgSentOnce
        Return
    PixelGetColor, notepadColor, %crossX%, %crossY%
    if ! ErrorLevel
    {
        Sendplay hello
        msgSentOnce = 1
    }
Return


You could also take out the msgSentOnce variable references and change
Code:
msgSentOnce = 1
to
Code:
SetTimer, isColorThere, off

It just depends on what you're trying to do if the color is found.
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Mon Jul 16, 2007 6:16 pm    Post subject: Reply with quote

a simple adjustment to your code, (though the other reply looks more useful)
Code:

wantedColor = 0xFFFFFF
crossX = 40
crossY = 78
Loop
{
  PixelGetColor, notepadColor, %crossX%, %crossY%
  if %ErrorLevel% = 0
    Break
  sleep 200
}
Sendplay hello

_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group