Jump to content
Sign in to follow this  
Schoening

PixelSearch Loop

Recommended Posts

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

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


"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!

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

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

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

This smells of game automation....


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

@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 :)


"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!

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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By AnRios
      Greetings friends!
      I have been searching the help file and Google, with no success, to find a way to validate images from a folder and mark them somehow in a spreadsheet.
      My context is: I made a code with the help of the community that captures images from SAP and saves them in a folder.  Now I'd like to identify which ones are black, if it's even possible. I read about PixelSearch, but did not get it to work. If someone could point me in the right direction, I'd appreciate it.
      The code I'm using:
      #include <File.au3> #include <ScreenCapture.au3> $x = InputBox("Title", "Amount of Images To Capture", "", "", 320, 150) If @error Then Exit $x = Number($x) $y = InputBox("Title", "Batch Name", "", "", 320, 150) If @error Then Exit $y = String($y) HotKeySet("{HOME}", "printscreen") Func printscreen() $FilePath =("C:\Fiscalizacao\Fotos"&"/") $FileName = $y & " - " $FileList = _FileListToArray($FilePath, $FileName & '*.jpg', 1) If Not IsArray($FileList) Then $FileName&= '1.jpg' Else $FileName &= $FileList[0] + 1 & '.jpg' EndIf _ScreenCapture_Capture($FilePath & "\" & $FileName, 354, 196, 673, 436) EndFunc HotKeySet("{BS}", "Terminate") Func Terminate() Exit 0 EndFunc For $i = 1 to $x Opt("WinTitleMatchMode",2) If NOT WinExists("Relatorio") Then MsgBox(0, "Atenção!", "Relatório do MOM deve estar aberto!") Call("Terminate") EndIf Opt("WinTitleMatchMode",2) WinActivate("Relatorio") Sleep (250) Opt("WinTitleMatchMode",2) SendKeepActive("Relatorio") Send("{ENTER}") Sleep (1000) Send("{HOME}") Sleep (200) Opt("WinTitleMatchMode",2) WinActivate("Relatorio") Send("{DOWN}") Next  
    • By plankton
      While IsArray(PixelSearch(100, 100, 300, 300, 0xffffff))     Send("{ESC}")     Sleep(1000) WEnd  MsgBox(0,"Loop exited","") Hi, above is my function that will execute ESC button when white color is present in specific area which is color 0xffffff.
      But how do I do the opposite like when white color is not present in that specific area? Like this below code which gives me error
       
      While IsArray(PixelSearch(100, 100, 300, 300, <>0xffffff))     Send("{ESC}")     Sleep(1000) WEnd  MsgBox(0,"Loop exited","")  
       
    • By plankton
      Hi I want it to search for a specific color in certain area then excute the loop which presses ESC button and stop the loop when the color no longer present in that specific area.  Here is the example of my code. But it doesnt stop when color is disappeared.
       
      Pixelsearch(511, 455, 678, 501, 0xFFFFFF)
      If Not  @Error Then
      While 1
      Sleep(1000)
      Send("{ESC}")
      Pixelsearch(511, 455, 678, 501, 0xFFFFFF)
      If @Error Then Exitloop
       
    • By Borges
      Sorry if I posted in wrong section but...
      how can I do something like that?
       
      If PixelSearch(660, 30, 670, 38, 0x242424, 0 , 1) <> @error Then
          Send("{F3}")
          Sleep(200)
       ElseIf PixelSearch(800, 30, 810, 38, 0x242424, 0 , 1) <> @error Then
          Send("{F4}")
          Sleep(200)
       EndIf
       
    • By Daka
      I find it very weird:
      if I run like this:
           Local $aCoord = PixelSearch($posX, $posY, $sizeX, $sizeY, '0xFF455E')
      works fine!
      If I run like this:
          Local $metaColor1 = '0xFF455E' or like this Local $metaColor1 = "0xFF455E" or Local $metaColor1 = "'0xFF455E'"
          Local $aCoord = PixelSearch($posX, $posY, $sizeX, $sizeY, $color)
      it doesn't want to work! So something with variable is not working and yes if I print it out like this:
      ConsoleWrite(@LF & $posX & ":"& $posY & ":"& $sizeX & ":" & $sizeY & ":" & $color&@LF)
      771:80:833:151:0xFF455E

      So I dont see the problem, maybe some of you people?
×
×
  • Create New...