Sign in to follow this  
Followers 0
GodForsakenSoul

shortening commands

6 posts in this topic

long time ago i stumbled upon a different language.

a crappy language which, while did do what i asked, didn't allow nice things like running files as standalone programs or making custom guis exactly as you wanted... and many other options probably.

what it did had, however, was the option to change a longass command into a short $x thing.

i'd like to know how it can be done in autoit. and if not exactly into $x, then to the shortest possible thing.

i'm working with image recognition right now, and i don't want a long line of "if pixelgetcolor(x,y)=xxx and pixelgetcolor(x1,y1)xxx1 and...".

i'm talking large objects like 25x25 points of reference.

Share this post


Link to post
Share on other sites



It depends how your script is structured. Many things can be shorten but it requires to identify the widely used commands around the script that are more appropriate within a function or other conditional structure. Hollow words, but a few lines of code can help here.

Share this post


Link to post
Share on other sites

i don't have an exact peice of code, but the idea is as follows:

if pixelgetcolor(x,y)=xxx and <repeat a good few dozen times> then

mousemove(x,y)

mouseclick("left")

elseif pixelgetcolor(x,y)=xxx1 and <again, repeat alot> then

call(Refill)

that's the code i'm planning i'm a gist. minus the upcoming debugging and losing retarded bugs such as 1 pixel offset

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I think functions can help you here... then you have one long line. and instead of doing "if xx and xx and xx" you could also write a loop to do that. Maybe a few more lines vertically, but a lot less characters and more readable. I don't know if the coordinates you want to check allow you to do that though...

Edited by CyberneticSoldier

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You need to use arrays for coordinates and maybe for colors and loop the array coordinates against the colors, for example:

Local $avCoords[3][2] = [[20, 30], [110, 120], [0, 200]]
Local $avClrs[5] = [0xABCDEF, 0xADBEEF, 0x112200, 0xFF20, 0xC33F00]

For $i = 0 To UBound($avCoords)-1
  If PixelGetColor($avCoords[$i][0], $avCoords[$i][1]) <> $avClrs[0] ExitLoop
Next

If $i < UBound($avCoords) Then
 ; Run another loop against different color for different times
Else
  Refill()
EndIf

You can shorten this code more by nesting looping say $i for coordinates and $j for number of colors. You can make it a function but it'll make sense if the same function get called by several or more points in your code.

Edited by Authenticity

Share this post


Link to post
Share on other sites

While the arrays method is probably better overall, to answer your posted question you could shorten PixelGetColor() by simply wrapping another function around it.

Func pgc($x, $y)
   
   Return PixelGetColor($x, $y)
   
EndFunc

Share this post


Link to post
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
Sign in to follow this  
Followers 0