Jump to content

I need help with Arrays and Errors.


Recommended Posts

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)

Link to comment
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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Fine, but which application do you try to automate?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...