Jump to content

Pixelsearch only uses first scan


Recommended Posts

Hi All,

I'm trying to make a script that has "nested" pixelsearches. However I'm stuck at the script always running the first line of code and not scan for the second one.
I have made this with the help of previous forum posts/the manual but i'm hitting a wall now :(

If anyone can point me in the right direction (or has a better way of doing this) i'm very gratefull :)

 

Local $Coords


HotKeySet("{F9}", "_start")
HotKeySet("^{F9}", "_start")

HotKeySet("{F10}", "_stop")
HotKeySet("^{F10}", "_stop")

HotKeySet("{F11}", "_exit")
HotKeySet("^{F11}", "_exit")


$run = True

while 1
    Sleep(500)
WEnd

Func _stop()
   ; Stop the script
    $run = False
EndFunc

Func _start()
    $run = True
    while $run
    ; Zoek naar Vooraad
    $location = PixelSearch(750, 293, 802, 346, 0XFF9717)
    If IsArray ($location) = 1 Then
     MouseClick ('left', $location[0], $location[1], 1)
     Sleep(5000)
     ;Voorraad niet gevonden, stop script
     ElseIf IsArray ($location) = 0 Then
      $run = False
    ; Zoek naar kruisje (misluke scan)
    $location = PixelSearch(750, 293, 802, 346, 0X455865)
   If IsArray ($location) = 1 Then
      MouseClick ('left', $location[0], $location[1], 1)
      ;Kruisje niet gevonden,
     ElseIf IsArray ($location) = 0 Then
      Sleep(500)
     EndIf
     EndIf
   WEnd

Thanks in advance for any reply :)

Link to comment
Share on other sites

First - NEVER use pixel search unless you have no other choice. It is very unreliable. 

Second - I see you are searching for stocks. Are you using a web browser for this?

  • If yes, then we can use different commands to access the browser and it's contents. 
  • If no, then what is the name of the application you are wanting to automate? We may already have a script that will do what you need and make things much easier for you.
Link to comment
Share on other sites

Hi Bert,

It's an Visual Fox Pro 9 application from arround 15 years old called Visipos. I doubt there is an script for that but who knows :)

The reason im using pixelsearch is limited knowledge I guess;

What it needs to do is basicly:

- Search and click an orange button.

- Search for blue button, if there is blue there is an error and seperate steps need to be taken (mousclicks) and then the script needs to start over and search for the orange button again and do the same mousclicks again if it finds blue.

- If Orange button is clicked and no blue is found it needs to search for "Button 1" and press it, do mouseclicks. Then Button 2 and so forth. If one of the button fails it needs to stop the script.

There are arround 5 "buttons" (products) that need to be pressed if visible. And once button 5 is pressed it needs to start back from the orange scan.
What it does now is search orange, click orange and repeat.

While it seems basic to press 6 buttons in a row I was hoping to relieve the people doing this once every x minute by automating it.
However my current script uses mouseclick and no pixelsearch in order with a sleep between but once "something" happens (the blue error) it keeps clicking anyway and changing things in the software which isn't good :)

It might be hard to explain so I hope it makes sense.

It's an old pc without internet or changing resolutions which is why I thought pixelsearch was good enough.
All it runs is this application and AutoIT.
If you have any better idea im all ears :)

 

Link to comment
Share on other sites

Based on the partial explanations you gave us, here what I did understand :

Opt ("MustDeclareVars", 1)

HotKeySet("{F9}", "_start")
HotKeySet("^{F9}", "_start")

HotKeySet("{F10}", "_stop")
HotKeySet("^{F10}", "_stop")

HotKeySet("{F11}", "_exit")
HotKeySet("^{F11}", "_exit")


Global $run

While 1
  Sleep(500)
WEnd

Func _stop()
  ; Stop the script
  $run = False
EndFunc   ;==>_stop

Func _exit()
  ; Exit the script
  exit
EndFunc   ;==>_stop

Func _start()
  Local $location
  $run = True
  While $run
    $location = PixelSearch(750, 293, 802, 346, 0xFF9717) ; search orange button
    If @error Then
      ; if no orange, what needs to be done ?
      Sleep (500) ; here to wait till it appears
      ContinueLoop
    EndIf
    MouseClick('left', $location[0], $location[1], 1) ; when found, click the orange button
    Sleep(5000)
    $location = PixelSearch(750, 293, 802, 346, 0x455865) ; search blue
    If not @error Then
      ; blue has appeared (means an error), what to do next ?
      MouseClick('left', $location[0], $location[1], 1) ; here to click the blue and start over
      Sleep (5000)
      ContinueLoop
    EndIf
    ; no blue means success then continue processing
  WEnd
EndFunc   ;==>_start

 

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