Sign in to follow this  
Followers 0
CalicoJack

Hopefully a simple question regarding If/Elseif/Else

4 posts in this topic

#1 ·  Posted (edited)

I am no programmer by any means, but I have loved to write small scripts to do little things here and there since AutoIt2.
 
Basically what I'm trying to do is have the script check my current window for 3 pixle color variables.  If any of them are detected do X, if none of them are detected do Y.

So like this;

Check for pixel color Var1,
If yes, Move it, Then Restart to check for pixel color Var1 again.
If no, Check for pixel color Var2
If yes, Move it, Then Restart to check for pixel color Var1 again.
If no, Check for pixel color Var3
If yes, Move it, Then Restart to check for pixel color Var1 again.
If none of the pixel colors are matched, Click here and do all the things.

Does this make sense?

This is what I got so far from using help files and examples I could find.  It works some of the time, but I dont know how to get it to reset once its detected Var1,Var2 or Var3. So right now it checks for Var1, and wether it detects it or not it continues checking for Var2 and Var3 respectivly.  Some of the time it just wants to click everything, some of the time it ignores everything lol. 

Global $Paused
Global $Var1 = PixelGetColor( 1084, 223, 0xA4B1B6) ;Detect Var1 (pixel color @ an x,y)
Global $Var2 = PixelGetColor( 1084, 238, 0xAAF807) ;Detect Var2 (pixel color @ an x,y)
Global $Var3 = PixelGetColor( 1077, 251, 0xAAF807) ;Detect Var3 (pixel color @ an x,y)

HotKeySet("{PAUSE}", "TogglePause")  ;Pause Key will pause script
HotKeySet("{ESC}", "Terminate")   ;ESC Key will kill script

Sleep ( 5000 )  ;5sec before macro starts looping


while (1)       ; Start : beginning of loop OR Func Start ()

If $Var1 = "0xA4B1B6" Then ;If it finds one then....
   MouseClickDrag ("left", 1094, 242, 1096, 100) ;...Move to (from first x,y to second x,y)
   Sleep ( 500 )
ElseIf $Var2 = "0xAAF807" Then ;If it finds one then....
   MouseClickDrag ("left", 1094, 242, 1096, 100) ;...Move to (from first x,y to second x,y)
   Sleep ( 500 )
ElseIf $Var3 = "0xAAF807" Then ;If it finds one then....
   MouseClickDrag ("left", 1094, 242, 1096, 100) ;...Move to (from first x,y to second x,y)
   Sleep ( 500 )
Else
    Sleep ( 1000 )
    MouseMove( 1107, 250) ;Move mouse to spot' )
    Sleep ( 1000 )
    MouseClick( "left", 1107, 250) ;Select spot
    Sleep ( 1000 )
    MouseDown( "left") ;Bring up menu
    Sleep ( 1000 )
    MouseClick( "left", 1200, 193) ;Option 2
    Sleep ( 1000 )
    MouseUp( "left")
    Sleep ( 1000 )
    MouseClick( "left", 752, 426) ; Confirm
    Sleep ( 2000 )
 EndIf

Sleep ( 2000 )

wend            ; Start
Edited by CalicoJack

Share this post


Link to post
Share on other sites



CalicoJack, welcome to the forum. You're doing a lot based on looking at pixels, which is often less than ideal. What kind of window/app are you trying to manipulate? 99% of the time, you can use commands like ControlSend or ControlClick, and be able to skip all the IF/Else - MouseClick stuff.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

CalicoJack, welcome to the forum. You're doing a lot based on looking at pixels, which is often less than ideal. What kind of window/app are you trying to manipulate? 99% of the time, you can use commands like ControlSend or ControlClick, and be able to skip all the IF/Else - MouseClick stuff.

Hi! Thank you :)

Yeah I know it is.  I looked into ControlSend/Click but doesn't seem likely for this little gimmick.  Originally it was part of a Minecraft script for collecting resources (yeah, don't ask lol)  Then my brother wrote a little java game we can play each other through direct TCP/IP, almost like chess, but not.  I think I found a way to drive him crazy with moves and at the same time hone my skills with autoit a little more using stuff I haven used before.

So the script has to be able to detect certain colors in certain spots.

Share this post


Link to post
Share on other sites

Please take a look at the forum rules before continuing (located in the bottom right of every page). We are here to help, but discussion of game automation is not allowed on the forum.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0