Sign in to follow this  
Followers 0
Schoening

PixelSearch Loop

13 posts in this topic

#1 ·  Posted (edited)

Hey i am trying to do a PixelSearch on the Screen, in a 3D environment.

The Idea is that the PixelSearch "Rotates Arround " In the 3D evironment, until it finds the Color. Then Moves Toward The Color.

To accomplish this, i made the PixelSearch Thin, But Tall:

PixelSearch(620,0,660,512, 0xFE4335,10)
(My resolution is 1280x1024 so the Center of X is 640)

Here is My Script:

WinActivate("3D Application")
Sleep(5000)

$KeyToPress = "w"
$D_Down  = "d"
Global $color = PixelSearch(540,0,740,512, 0xFE4335,50)


Func Spin()
Send ("{"&$D_Down&" DOWN}")
    Sleep (200)
    Send ("{"&$D_Down&" UP}")
EndFunc

Func WalkDistance()
Send ("{"&$KeyToPress&" DOWN}")
Sleep ($color[1]*2000)
Send ("{"&$KeyToPress&" UP}")
EndFunc


Select
Case Not @error
  Sleep(10)
  MouseMove ($color[0],$color[1],10)
        Call("WalkDistance")
Case @error
  Sleep(10)
  Call("Spin")
Case Else
     MsgBox(0,"Error","Error")
EndSelect
MsgBox(0,"Message","Done")

The First Case Works, But is not Shutting Down.

The Second Case Steps in when there are no Pixels of that Color, and Rotates

I want to Repeat the Select until the Application Window is No Longer The Active window.

How can i Repeat The Select Case?

Can i Run a Select Case inside a Select Case by using If ... Then ?

Is Select Case a Good Way to Make a Programm work with Diffrent Scenarios (Cases) or is there a better way?

:) This Language is Fast and fun to Learn ! ;)

Edited by Schoening

Share this post


Link to post
Share on other sites



bump

Share this post


Link to post
Share on other sites

Hi, Schoening. Please don't bump in less than 24 hours. It gives us the chance to have our coffee and review your question :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Hi, Schoening. Please don't bump in less than 24 hours. It gives us the chance to have our coffee and review your question :)

Allrigh, sorry ;)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

So now i have tried to Put the Select Case into a Function:

WinActivate("3D Application")
Sleep(5000)
$KeyToPress = "w"
$D_Down  = "d"
Global $color = PixelSearch(540,0,740,512, 0xFE4335,20)
While 1
Sleep(1000)
Sleep(4000)
Call("_select")
WEnd

Func Spin()
Send ("{"&$D_Down&" DOWN}")
    Sleep (200)
    Send ("{"&$D_Down&" UP}")
EndFunc

Func WalkDistance()
Send ("{"&$KeyToPress&" DOWN}")
Sleep (2000)
Send ("{"&$KeyToPress&" UP}")
EndFunc

Func _select()
Select
Case Not @error
  Sleep(10)
  MouseMove ($color[0],$color[1],10)
        Call("WalkDistance")
Case @error
  Sleep(10)
  Call("Spin")
Case Else
     MsgBox(0,"Error","Error")
EndSelect
EndFunc
MsgBox(0,"Message","Done")

But Instead of Calling Case @error when there is no Pixel of the Righ Color. It just Crashes

Error Message:

(38) : ==> Subscript used with non-Array variable.:

In that line:

MouseMove ($color[0],$color[1],10)

So the first Case Repeats If the PixelSearch that runs before the Loop was Not @error. Else It Crashes..

Also, The PixelSearch is Defined before the Loop, and does not change. I need to Start PixelSearch everytime The Loop Calls for Func _Select()so the Values of $color change before the Select Statement or i get trapped in a Infinite Loop of Case Not @error

Edited by Schoening

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@LaCastiglione Spongebob fan ? ;)

@kaotkbliss Yeah well.. It's Like the Durian Fruit.. The Smell is bad, but it's still a good tasting fruit.

One hint: Your edit pretty much sums up your fix...

I will Look into It.. But i can't see it Right Now :)

Ps. For Future Topics i will be less specific, i don't want to get a ban for Giving a Idea of what i am doing

Edited by Schoening

Share this post


Link to post
Share on other sites

Ps. For Future Topics i will be less specific, i don't want to get a ban for Giving a Idea of what i am doing

Or you could just follow the rules :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Im gonna Try a Return Function

Share this post


Link to post
Share on other sites

One hint: Your edit pretty much sums up your fix...

This smells of game automation....

;)

I think i got what you mean:

Func _select()
Local $color = PixelSearch(540,0,740,512, 0xFE4335,20)
Select
Case Not @error
  Sleep(10)
MouseMove ($color[0],$color[1],10)
        Call("WalkDistance")
Case @error
  Sleep(10)
  Call("Spin")
Case Else
     MsgBox(0,"Error","Error")
EndSelect
EndFunc

That works, thx for help all :)

Share this post


Link to post
Share on other sites

Schoening,

Please make sure you follow the Forum Rules in future. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Schoening,

Please make sure you follow the Forum Rules in future. ;)

M23

Yeah i will.. I though i did though :)

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
Sign in to follow this  
Followers 0

  • Similar Content

    • Cyberjunk
      By Cyberjunk
      Hello, I am new to both Programming and this forum. I have done a few tiny projects that were successful and fell in love with Autoit. So now I am trying to learn new things as I go. I have read the Help docs on my following question, I have gone thru all of that. and I am sure as soon as you see my code you will be saying OMG why did he do that, or OMG how can you forget to add this.. But when your new you take the path of least resistance to get the outcome you want.

      SETUP:
      I am trying to make a code that will open a piece of software, then open a browser (which has a handful of tabs already open) go to a web page (one of the tabs) and search an area of the web page for a specific color, if that color is found I want it to close the browser and go back and start again. If that color is not found on that page I want it to switch tabs and search that page for the color. If the color is found on that page I want it to close the browser and start again. If the color is not found on either page, I want it to open another browser and go to website and do some things I will add once i get past this obstacle.

      I already have it almost there my code will open my software, open the browser, do the searches, find or not find the color, the part I am having trouble with is the if and else and what happens if and what it does if it does not. So the first code I have does everything I want except if it finds the color on the first run it closes the browser, but then when it starts the process again it doesnt check for the color. its like it skips the scanning part and goes straight to the opening of the second browser and finishes the code.
      Run( "C:\Programs\myprogram.exe", "", @SW_SHOWDEFAULT ) Sleep(4000) MouseClick("left", 613,272) ;click in program Sleep(500) Example() Func Example() MouseClick("left", 632,456) ;click in program Sleep(500) MouseClick("left", 527,456) ;click in program Sleep(15000) Run( "C:\Programs\browser1.exe", "", @SW_SHOWMAXIMIZED ) Sleep(Random(4000,6000)) EndFunc ;==>Example MouseClick("left", 162,14) ;switch tab Sleep(Random(5000,8000)) MouseClick("left", 354,14) ;switch tab Sleep(Random(5000,8000)) $aCoord = PixelSearch(873, 485, 900, 600, 0xDD0000, 10) ;search for color If Not @error Then MouseClick("left", 1338,6) ;close browser1 Sleep(1000) Call("Example") Else MouseClick("left", 162,14) ;switch tab Sleep(1000) EndIf MouseClick("left", 162,14) ;click tab again just to be sure its loaded Sleep(4000) $aCoord = PixelSearch(1052, 308, 1120, 431, 0xFF0000, 10) ;search for this color If Not @error Then MouseClick("left", 1338,6) ;close browser1 Sleep(1000) Call("Example") Else Run( "C:\Programs\browser2.exe", "", @SW_SHOWMAXIMIZED ) Sleep(2000) EndIf MouseClick("left", 134,45) ;click on address bar Sleep(1000) Send("aspecificwebpage.com") ;input website Send("{enter}") ;hit enter Sleep(15000) MouseClick("left", 1338,6) ;close browser2 Sleep(500) MouseClick("left", 1338,6) ;close browser1 Sleep(500) MouseClick("left", 625,454) ;click in program Sleep(500) MouseClick("left", 634,271) ;click in program Sleep(500) MouseClick("left", 917,245) ;close program Sleep(500) SO it makes the first scan and is successful, if the color is found it closes as I want, but then when nit starts the code again it does not scan anything the second time.

      and on the other side, if the color is not found naturally everything works as it is written.
      I want to guess by all the weird colors in the code sniplet I have a massive amount of errors. It is like a rainbow of text up there. different from what i see in AutoIT

      Any help would be appreciated.

       
    • Nitrolord
      By Nitrolord
      I had this problem with PixelGetColor not giving me the same HEX Color as the AU3Info Tool and searched every were with no luck then had a OH DA moment LoL.
      The problem is that the
      "PixelGetColor ($mouseX[0], $mouseY[1])"
      is looking rite at the very tip of the mouse pointer not under it.  So you have to set a -3 after the [0] and [1].  
      "PixelGetColor ($mouseX[0] -3, $mouseY[1] -3)"
      to make it search next to the pointer not on the pointer.  You may have to adjust this a bit for your display but you should not have  to go more then -5.  -3 seems to work best for me.
      Example.au3
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 141, 127, 276, 231) $Input1 = GUICtrlCreateInput("", 8, 8, 121, 21) $Label1 = GUICtrlCreateLabel("Press or Hold F1 to get Hex color at Mouse X -3, Y-3 Pos,", 8, 40, 124, 73) GUISetState(@SW_SHOW) HotKeySet("{f1}","MousePos") Func MousePos() $aPos = MouseGetPos() $PGC = PixelGetColor($aPos[0] -3, $aPos[1] -3) GUICtrlSetData($Input1, "0x" & Hex($PGC, 6)) EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
    • DuyAnh
      By DuyAnh
      how to find the location on an image color ?? 
      Similar PixelSearch, but in a format bmp image

      search 0x0806EB and returns coordinates

      sorry I am not good at English
    • Tirk
      By Tirk
      PixelSearch in a GUI window which state's @SW_MINIMIZE.
      Is it possible?
    • Annonyreeder
      By Annonyreeder
      Hello,
      I've wrote a fairly straight forward script that will search an area of the screen and then left click on apart of that area should it find a certain color/pixel. 
      I have a small issue where by within the area, multiple pixels of the same color will appear, the script will continue to click on the same pixel over and over again. Is there a way so that it will cycle through all the results and click on each one for a given time period then move onto the next, as apose to clicking on the same spot forever. I have used timers before and that shouldn't be an issue, its more the having it stop clicking, or ignoring the current pixel its clicking and then moving onto the next one (same pixel color within same area).

      Hopefully this makes sense.
      [autoit]
      HotKeySet("{ESC}", "END_EXIT") HotKeySet("+1", "start") While 1     Sleep(100)  WEnd func start()    while 1 $location = PixelSearch( 631, 175, 1181, 597, 0xFF0000) If IsArray ($location) = 1 Then     MouseClick ('left', $location[0], $location[1], 1, 0)  EndIf  WEnd EndFunc  func END_EXIT()  Exit  EndFunc
       
      [/autoit]