AutoHotkey Community

It is currently May 26th, 2012, 10:04 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Looping an Expression
PostPosted: October 17th, 2009, 6:11 pm 
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 :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2009, 7:25 pm 
Online

Joined: April 8th, 2009, 7:49 pm
Posts: 6065
Location: San Diego, California
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/Variable ... xpressions
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2009, 8:12 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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

}

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2009, 9:22 pm 
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...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2009, 9:41 pm 
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
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2009, 11:25 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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
  }
}

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: dra, Google [Bot], hyper_, JSLover, Leef_me, patgenn123 and 59 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group