Jump to content

Recommended Posts

Last time I used AutoIT was 3 years ago and already then I wasn't very good at coding/scripting. I got very low experiences in programming and have only been using Visual Basic (6 and .net) and AutoIT.

Now however, I've already run into a problem that I don't understand of what's wrong.

Here what I got

Func Test()
  $Click = PixelSearch(822, 550, 860, 565, 0x3B5998)
  Sleep(1000)
   if @error Then
   MsgBox("Error","The pixels was not found.")
   Else
   Mouseclick("left",$Click[0], $Click[1])
   EndIf
EndFunc

When I got the color in this coordination, the mouse goes to the coordination and making a left click. Just as I want.

However, when I don't got the color in the coordination, I'm getting up an error on the Mouseclick line. It says the [0] is error (if I understand it right).

I don't understand. Because wont it be registered as an @error when the pixelsearch isn't found? What I see from my old script I got it very similar.

When I look at the guide it says @error is set to 1, so even if I try to make it If @error = 1 then instead, it will still give me error on the same line as before.

Anybody who would like to help?

Also is there more tutorials? I've read the 4 tutorials in the help file, but then it's just functions and stuffs, ofc I guess I can read one by one from there, but if somebody got more tutorials that me as a beginner can follow for being a pro in AutoIT, it would be very nice.

also I tried this, but still same error!

Func Test()
  $Click = PixelSearch(822, 550, 860, 565, 0x3B5998)
  Sleep(1000)
   if @error = 1 Then
   MsgBox("Error","The pixels was not found.")
   Elseif @error = 0 Then
   Mouseclick("left",$Click[0], $Click[1])
   EndIf
EndFunc

Thanks in advance!

Edited by Lucidity
Link to post
Share on other sites
  • Moderators

Lucidity,

Welcome to the Autoit forum. :oops:

If PixelSearch fails then you do not get an array of coordinates returned - so the script crashes when you try to read the elements. And when you check @error you are actually checking Sleep which rarely errors in my experience. :doh:

Use IsArray to test like this:

$Click = PixelSearch(822, 550, 860, 565, 0x3B5998)
Sleep(1000)
If IsArray($Click) Then
    Mouseclick("left",$Click[0], $Click[1])
Else
    MsgBox("Error","The pixels was not found.")
EndIf

Try that and see how you get on. :bye:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...