About8Bobcats

Loop Working Incorrectly

4 posts in this topic

#1 ·  Posted

So I can't get this to loop properly. I've tried while loops but the problem with that is once it figures out what if statement to use it will loop that same one endlessly. The script works fine when I manually loop it (F5) -- Any ideas? This is only my second day into this language :\

HotKeySet("{F1}","myExit")


Global $var1 = Hex(PixelGetColor(1412, 95), 6)
Global $var2 = Hex(PixelGetColor(1499, 124), 6)

   ;Check if var1 is blue and var2 is green
if $var1 = "1A2134" And $var2 = "373317" Then
  MsgBox("","","Success",1)
  MouseMove(1313,72)
  MouseClick("Left")
  MouseMove(1456,77)
  Sleep(500)
EndIf

   ;Check if var1 is green and var2 is blue
if $var1 = "3D3113" And $var2 = "172336" Then
  MsgBox("","","Success",1)
  MouseMove(1313,72)
  MouseClick("Right")
  Sleep(500)
  MouseClick("Left")
  MouseMove(1456,77)
  Sleep(500)
EndIf

Func myExit()
   MsgBox(0, "Attention", "Your bot has been terminated.")
   Exit
EndFunc

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

Welcome to AutoIt and the forum!

Can you please tell us which program you try to automate? Pixel functions and MouseMove to fixed coordinates is not very reliable as it depends on screen resolution and and window postion.
There are - most of the time - more reliable ways to do what you want to do.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

40 minutes ago, water said:

Welcome to AutoIt and the forum!

Can you please tell us which program you try to automate? Pixel functions and MouseMove to fixed coordinates is not very reliable as it depends on screen resolution and and window postion.
There are - most of the time - more reliable ways to do what you want to do.

Thanks.

It's for a game however nothing is moving in the game until the mouse is clicked. getting pixel information is something that must be done because there's different colours in a static area after each mouse click. My screen resolution and position is always the same so that should be good. I know I probably could have put each if statement into an array or function but that's a little too complex for me at the time.

 

I'm not quite sure if you understood completely what I mean't but this is what I did before;

HotKeySet("{F1}","myExit")


Global $var1 = Hex(PixelGetColor(1412, 95), 6)
Global $var2 = Hex(PixelGetColor(1499, 124), 6)

While 1
   ;Check if var1 is blue and var2 is green
if $var1 = "1A2134" And $var2 = "373317" Then
  MsgBox("","","Success",1)
  MouseMove(1313,72)
  MouseClick("Left")
  MouseMove(1456,77)
  Sleep(500)
EndIf

   ;Check if var1 is green and var2 is blue
if $var1 = "3D3113" And $var2 = "172336" Then
  MsgBox("","","Success",1)
  MouseMove(1313,72)
  MouseClick("Right")
  Sleep(500)
  MouseClick("Left")
  MouseMove(1456,77)
  Sleep(500)
EndIf
Wend

Func myExit()
   MsgBox(0, "Attention", "Your bot has been terminated.")
   Exit
EndFunc

 

But the while would loop the same mouse movement  

Share this post


Link to post
Share on other sites

#4 ·  Posted

Seems you missed to read the forum rules on your way in.
Please do so no. Especially the part about game automation. This isn't allowed here.

Hence you won't get any help on this subject.

Hope to see you soon with a legitimate question :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.