Jump to content

Wait until pixel is found then start


Recommended Posts

I am trying to create a script that will wait until a pixel is found. After the pixel is found then it will start moving the mouse. And also why is my script exiting when i use #RequireAdmin?

My code
 

#RequireAdmin
AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("PixelCoordMode", 0)

HotKeySet("t" ,"set")

Global  $pix = PixelSearch(235,209,287,260,0xA53A3A,10)

Func set()
   Do
      $pix = PixelSearch(235,209,287,260,0xA53A3A,10)
   Until @error

   MouseClick('primary', $pix[0], $pix[1]
EndFunc

While 1
   Sleep(300)
WEnd

 

Edited by Bamse
Missing code
Link to post
Share on other sites
  • Developers
46 minutes ago, Bamse said:

I am trying to create a script that will wait until a pixel is found. After the pixel is found then it will start moving the mouse.

... but you are doing the PixelSearch() only one time at the start of the script so there seems to be a logic issue.

 

47 minutes ago, Bamse said:

And also why is my script exiting when i use #RequireAdmin?

How did you determine this? or are you talking about that SciTE tells you it ended but it is still running?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
19 minutes ago, Jos said:

How did you determine this? or are you talking about that SciTE tells you it ended but it is still running?

Jos

The program keeps running but i can’t get any outputs from ConsoleWrite etc...

 

19 minutes ago, Jos said:

... but you are doing the PixelSearch() only one time at the start of the script so there seems to be a logic issue.

But shouldn't it do the MouseClick when thel Do loop have found the pixel? Pix is a global Variable.

Edited by Bamse
Link to post
Share on other sites
  • Developers
Just now, Bamse said:

he program keeps running but i can’t get any outputs from ConsoleWrite etc...

That will only work when you run SciTE as Administrator since an lower level process can't read the STDOUT of an elevated level process.

1 minute ago, Bamse said:

But shouldn't it do the MouseClick when thel Do loop have found the pixel?

Why? Are you starting  func Set() somewhere in your script?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
  • Developers

Ok. So lets look at your loop checking for the pixel. 
You are looping until @error right? When will PixelSearch() return an @error of 1  and exit this loop?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
1 minute ago, Jos said:

You are looping until @error right? When will PixelSearch() return an @error of 1  and exit this loop?

I have been reading the help file that Autoit comes with and the failure will return one when the color is not found.
Is the loop exiting when it returning one?

Link to post
Share on other sites
  • Developers
2 minutes ago, Bamse said:

Is the loop exiting when it returning one?

Yes, the loop is ending when @error is not equal to 0.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
18 minutes ago, Jos said:

Yes, the loop is ending when @error is not equal to 0.

Then the loop is ending when it has found the pixel, right? 
 

Func set()
   Run("D:\Program Files\SWT\server.exe")

   WinWait("server1")
   WinActivate("server1")
   WinMove("server1", "", 0, 0, 848, 704)

   Global  $pix = PixelSearch(235,209,287,260,0xA53A3A,10)

   Do
      $pix = PixelSearch(235,209,287,260,0xA53A3A,10)
   Until @error

   MouseClick('primary', $pix[0], $pix[1]

EndFunc

It looks like the program is exiting when it has found the color.

Edited by Bamse
Link to post
Share on other sites
  • Developers
5 hours ago, Bamse said:

Then the loop is ending when it has found the pixel, right? 

Come on ... think, it isn't that hard!! Of course the reverse of what you want is happening.
PixelSearch() sets @error to 1 when it is unsuccessful and your loop ends.    

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
4 hours ago, Jos said:

Come on ... think, it isn't that hard!! Of course the reverse of what you want is happening.
PixelSearch() sets @error to 1 when it is unsuccessful and your loop ends.    

Jos

That hit me when i was working out, but i need to figure out some code that will work!
Will be back with my code if i can’t solve it!
Thanks again @Jos

This is really hard(Banging my head against the keyboard) but fun at the same time.

Edited by Jos
Link to post
Share on other sites
  • Developers

Hints has been given, actually the answer was given,  and you really need to be able to figure that one out by yourself.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...