Jump to content

Recommended Posts

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

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

  • Moderators
Posted

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

 

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
×
×
  • Create New...