EvilOniLink

I need help with Arrays and Errors.

8 posts in this topic

I have a code that looks for many colors and when it finds one of them it clicks it. I would like to put all of the colors into a category or array so that I could shorten the code.

Func Start()
 While 1
  $Color1 = PixelSearch(5, 99, 1140, 725, 0xE2CC4C)
  $Color2 = PixelSearch(5, 99, 1140, 725, 0xE2E159)

  If IsArray($Color1) Then
   MouseClick("primary", $Color1[0], $Color1[1])
   Sleep(Random(12000, 13000, 1))
  ElseIf IsArray($Color2) Then
   MouseClick("primary", $Color2[0], $Color2[1])
   Sleep(Random(12000, 13000, 1))

  EndIf

 WEnd
EndFunc

This is fine for a couple of colors but if I have 20 or more colors the code gets lengthy and I'd much rather just have a collection of colors and then a command that calls all of those colors during a pixel search. for example:

Local $Colors[3] = ["Color 1", "Color 2", "Color ect."]

$Colors[0] = 0xE2CC4C

$Colors[1] = 0xE2E159

$Colors[2] = ect.

Func Start()
 While 1
  $Colors = PixelSearch(5, 99, 1140, 725, $Colors)

Share this post


Link to post
Share on other sites



pseduo code.

 

array[]=[0xE2CC4C, 0xE2E159,etc]

 

while

for i=0 to array count -1

$colorpos= PixelSearch(5, 99, 1140, 725, array[$i])

if is array($colorpos) then

 MouseClick("primary", $colorpos[0], $colorpos[1])
   Sleep(Random(12000, 13000, 1))

endif

$colorpos=0

next

wend

 

Saludos

Share this post


Link to post
Share on other sites

Can you please tell us why you need to search for 20 different colors?
Pixelsearch and Mouseclick are not very reliable (depend on screen resolution and window postion) and most of the time there are 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

Thank you Danyfire. Water, because there are a bunch of different colors and I want to click which ever one shows up.

Share this post


Link to post
Share on other sites

Fine, but which application do you try to automate?


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

@Water: It must be a Online-Game, serious other applications don't need a random sleep.

Func Start()

 While 1
  $Color1 = PixelSearch(5, 99, 1140, 725, 0xE2CC4C)
  $Color2 = PixelSearch(5, 99, 1140, 725, 0xE2E159)

  If IsArray($Color1) Then
   MouseClick("primary", $Color1[0], $Color1[1])
   Sleep(Random(12000, 13000, 1))
  ElseIf IsArray($Color2) Then
   MouseClick("primary", $Color2[0], $Color2[1])
   Sleep(Random(12000, 13000, 1))

  EndIf

 WEnd
EndFunc

Share this post


Link to post
Share on other sites

OK, I'm going to report this.
Maybe the OP is more willing to explain what he needs the code for when a Mod asks :)


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

Go ahead and report it. I never read in the agreements that you had to tell everyone what you were doing and why. Plus I already got what I needed :P

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