Jump to content

Simple script that doesn't work


Recommended Posts

Hi all, it's my first post here and my second day using autoit (I've used it for some hours).

I wanted to make a very simple first script: I just wanted autoit to click randomly in a rectangle and, between every click, it pauses from 5 to 10 seconds randomly. In the meantime it should check another area of the screen and search for a colour: if it finds it, it moves the cursor over it and clicks it, then continues clicking randomly and so on. Just let me show you with a picture: http://oi48.tinypic.com/2pqqaac.jpg

The code is:

$i = 0

Do ;starts a loop

$coord = PixelSearch(101, 71, 729, 628, 0xFEFFD2) ; searches 0xFEFFD2 in a rectangle

MouseClick("left", Random(817, 992, 1), Random(504, 609, 1), 1) ;clicks randomly in another area

Sleep(Random(5000, 10000, 1)) ;waits from 5 to 10 seconds

if not @error then

MouseMove($coord[0],$coord[1],0)

Sleep (3000) ;moves over the pixel and waits 3 seconds

MouseClick("left",$coord[0],$coord[1])

Sleep (3000) ;clicks the pixel and waits 3 seconds

EndIf

Until $i = 0

I know you are veterans of autoit, but I added comments so that you can clearly understand what I wanted it to do. When I run the script it clicks once in the random click area and then a messagge appears saying subscript used with non-array value. I've searched it on the internet and on the forum, but I always get into scripts that are too much different from mine, and so I don't get how to solve this problem. Thanks a lot for the attention and sorry if my English isn't perfect

Edited by Neversleep
Link to comment
Share on other sites

  • Moderators

Hi, neversleep, welcome to the forum. Can you clarify "click in a rectangle"? Is this searching the window of an application, or a rectangle you've drawn? If an application, what application are you trying to capture? There may be infinitely easier ways of accomplishing what you would like to do. ;)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thanks for the welcome and for the answer too ;) The rectangles are "two pieces" of a window (Mozilla Firefox), and they are two: the bigger one is on the left side and is nearly a square, the second one is smaller and is located on the right bottom of the window

Link to comment
Share on other sites

Look where you have "if not @error then"

It id checking to see if "Sleep(Random(5000, 10000, 1))"

Try

$i = 0

Do ;starts a loop

$coord = PixelSearch(101, 71, 729, 628, 0xFEFFD2) ; searches 0xFEFFD2 in a rectangle

$error = @error

MouseClick("left", Random(817, 992, 1), Random(504, 609, 1), 1) ;clicks randomly in another area

Sleep(Random(5000, 10000, 1)) ;waits from 5 to 10 seconds

if not $error then

MouseMove($coord[0],$coord[1],0)

Sleep (3000) ;moves over the pixel and waits 3 seconds

MouseClick("left",$coord[0],$coord[1])

Sleep (3000) ;clicks the pixel and waits 3 seconds

EndIf

Until $i = 0

EDIT:

And of course, that loop will only run once since $i = 0 always

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Ok, now it works ;) But it does not recognise the colour because it moves the mouse over wrong places...the colour I want it to click is kinda white, and for example it clicked in a black area two or three times (not three times in a row, but for free times)...tips ? Group of colours maybe ? Can I give autoit the order to click something that is very similar to a picture I want ?

Edited by Neversleep
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...