Jump to content
Sign in to follow this  
asym

Pixel Searcher not working

Recommended Posts

asym

Ok my idea is to make a script that searches for 1 color in the screen and if it finds that color it will kill/close one process, the code I have made is below but for some reason its not working and When I run it, it immediatly closes

HotKeySet("{F9}", "StartScript")
$script = False

ToolTip("F9 = Start/Stop Script", 0, 0)


Func StartScript()
    If $script = False Then
        $script = True
    Else
        $script = False
        ToolTip("F9 = Start/Stop Script", 0, 0)
    EndIf
EndFunc   ;==>StartScript

While $script = True
    Dim $cordinates = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0xFFF200)
    If Not @error Then
        If ProcessExists("rPE.exe") Then
            ProcessClose("rPE.exe")
        EndIf
    EndIf
WEnd

If anyone could help me it would be great

Share this post


Link to post
Share on other sites
Shakala

Well, i didnt look at all your code but with a quick glance, you have nothing to keep the bot running. Just add

While 1 
Sleep(100)
wend

after your tooltip line

~Shakala

Edited by Shakala

Share this post


Link to post
Share on other sites
AdmiralAlkex

Hi and Welcome to the forums!

Did you really think that through? First you declare @script as False, and then you have a loop that asks it to be True. Thus the loop never runs, and what do you have after it? Nothing. So nothing happens (it exits).

I think what you want is closer to:

HotKeySet("{F9}", "StartScript")
$script = False

ToolTip("F9 = Start/Stop Script", 0, 0)
Sleep(2000)     ;So we have time to read it
ToolTip("")     ;Remove the ToolTip

While 1
    Sleep(10)       ;We don't want to use up the whole cpu do we?
    While $script = True
        Dim $cordinates = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0xFFF200)
        If Not @error Then
            If ProcessExists("rPE.exe") Then
                ProcessClose("rPE.exe")
            EndIf
        EndIf
    WEnd
WEnd

Func StartScript()      ;functions are normally placed last, make it easier to browse the code
    If $script = False Then
        $script = True
    Else
        $script = False
        ToolTip("F9 = Start/Stop Script", 0, 0)
        Sleep(2000)
        ToolTip("")
    EndIf
EndFunc   ;==>StartScript

Share this post


Link to post
Share on other sites
asym

The least I can do is thank you for your kindness and for helping me...

Im sorry I seem a bit newbie its like my 3rd script in autoit and I couldnt make it work...

Yet, I wasnt able to get what was wrong with the code... Could you give me a little tip?

And sorry probably the best way to start in these forums would be to introduce myself in other section, ill do that right away

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.