Bamse

Wait until pixel is found then start

14 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites
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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


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

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

I am using  HotKeySet("t" ,"set") for starting the function. 

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


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?

Share this post


Link to post
Share on other sites
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.

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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
1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#12 ·  Posted

@Jos  Could you give me a hint what i need todo to getting it working?

Share this post


Link to post
Share on other sites

#13 ·  Posted

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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