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 

Looping an Expression

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





PostPosted: Sat Oct 17, 2009 5:11 pm    Post subject: Looping an Expression Reply with quote

Code:
BaseCoord1=147
BaseCoord2=91
BaseCoord3=171
BaseCoord4=130
Loop
{   
PixelSearch, Px, Py, %BaseCoord1%, %BaseCoord2%+(42*(a_index-1)), %BaseCoord3%, %BaseCoord4%+(42*(a_index-1)),%Green%, 0, Fast
if ErrorLevel
.....
}

Basically I want it to move down 42 pixels every iteneration of the loop and search a different area... help please Very Happy
Back to top
Leef_me



Joined: 08 Apr 2009
Posts: 1158
Location: San Diego, California

PostPosted: Sat Oct 17, 2009 6:25 pm    Post subject: Reply with quote

In your script, remove all the % in the PixelSearch command. Read on for the reason why. BTW, how do you plan to end your loop ?

http://www.autohotkey.com/docs/commands/PixelSearch.htm
X1,X2,X3,X4 The X and Y coordinates ... corner(s) of the rectangle to search, which can be expressions.

http://www.autohotkey.com/docs/Variables.htm#Expressions
Quote:
Expressions are used to perform one or more operations upon a series of variables, literal strings, and/or literal numbers.

Variable names in an expression are not enclosed in percent signs (except for arrays and other double references). Consequently, literal strings must be enclosed in double quotes to distinguish them from variables.


Just for fun, I changed your search into mousemoves (which also use expressions). With the % in place there was no movement.
Code:
BaseCoord1=147
BaseCoord2=91
BaseCoord3=171   ; +500 ; for testing
BaseCoord4=130

Loop
{   
;PixelSearch, Px, Py, %BaseCoord1%, %BaseCoord2%+(42*(a_index-1)), %BaseCoord3%, %BaseCoord4%+(42*(a_index-1)),%Green%, 0, Fast

MouseMove, BaseCoord1, BaseCoord2+(42*(a_index-1)), 10
sleep, 100

MouseMove, BaseCoord3, BaseCoord4+(42*(a_index-1)), 10
}

esc::
exitapp
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 2428

PostPosted: Sat Oct 17, 2009 7:12 pm    Post subject: Reply with quote

Seems like setting the addition into the PixelSearch statement itself is making this more complex than necessary, you really only need to add the pixels if the color was not found (ErrorLevel =1):

Code:
BaseCoord1=147
BaseCoord2=91
BaseCoord3=171
BaseCoord4=130
Loop {   
PixelSearch, Px, Py, %BaseCoord1%, %BaseCoord2%, %BaseCoord3%, %BaseCoord4%,%Green%, 0, Fast
if ErrorLevel=1
  BaseCoord2+=42, BaseCoord4+=42

}

_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message
Guest






PostPosted: Sat Oct 17, 2009 8:22 pm    Post subject: Reply with quote

sinkfaze wrote:
Seems like setting the addition into the PixelSearch statement itself is making this more complex than necessary, you really only need to add the pixels if the color was not found (ErrorLevel =1):

Code:
BaseCoord1=147
BaseCoord2=91
BaseCoord3=171
BaseCoord4=130
Loop {   
PixelSearch, Px, Py, %BaseCoord1%, %BaseCoord2%, %BaseCoord3%, %BaseCoord4%,%Green%, 0, Fast
if ErrorLevel=1
  BaseCoord2+=42, BaseCoord4+=42

}

I'm checking multiple items, so if add 42 every time it will screw it up...
Back to top
Guest






PostPosted: Sat Oct 17, 2009 8:41 pm    Post subject: Reply with quote

Quote:
I'm checking multiple items, so if add 42 every time it will screw it up...



Code:
BaseCoord1=147
BaseCoord2=91
BaseCoord3=171
BaseCoord4=130
Coord2:=BaseCoord2, Coor4:=BaseCoord4
Loop {   
PixelSearch, Px, Py, %BaseCoord1%, %Coord2%, %BaseCoord3%, %Coord4%,%Green%, 0, Fast
if ErrorLevel=1
  Coord2+=42, Coord4+=42
}
Back to top
sinkfaze



Joined: 18 Mar 2008
Posts: 2428

PostPosted: Sat Oct 17, 2009 10:25 pm    Post subject: Reply with quote

Anonymous wrote:
I'm checking multiple items, so if add 42 every time it will screw it up...


Not if you start over from the beginning; the variables will reset to their default values before re-entering the loop. For instance:

Code:
!j::
BaseCoord1=147
BaseCoord2=91
BaseCoord3=171
BaseCoord4=130
Loop {   
PixelSearch, Px, Py, %BaseCoord1%, %BaseCoord2%, %BaseCoord3%, %BaseCoord4%,%Green%, 0, Fast
if ErrorLevel=1
  BaseCoord2+=42, BaseCoord4+=42
else if !ErrorLevel {
  << some action >>
  break
  }
}
return


or:

Code:
BaseCoord1=147
BaseCoord2=91
BaseCoord3=171
BaseCoord4=130
Loop {   
PixelSearch, Px, Py, %BaseCoord1%, %BaseCoord2%, %BaseCoord3%, %BaseCoord4%,%Green%, 0, Fast
if ErrorLevel=1
  BaseCoord2+=42, BaseCoord4+=42
else if !ErrorLevel {
  << some action >>
  BaseCoord2=91, BaseCoord4=130
  break
  }
}

_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message
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