Jump to content

sleep comman? or not


Recommended Posts

OK i have a question, kinda noob question but, how do i make a script run slower not the sleep command but how many times it reads all the commands. because it seems like its flying through the au3 and lagging out my computer.

here is the code im using.........

CODE
sleep (2000)

WinActivate("SRO_Client")

sleep (2000)

Global $Paused

HotKeySet("z", "Pause")

Func Pause()

$Paused = NOT $Paused

While $Paused

Sleep (400)

WEnd

EndFunc

Func fight()

$coord = PixelSearch( 100, 100, 900, 525, 0xa00a00, 1, 2)

If Not @error Then

MouseMove($coord[0],$coord[1],0)

Sleep (100)

MouseClick("left",$coord[0],$coord[1])

Sleep (500)

if (pixelgetcolor (429,21) = 0x2C89CB) then

send ("1")

send ("2")

endif

EndIf

;send ("{left 6}")

EndFunc

while 1=1

fight()

wend

this basically just looks for a color and executes 2 different buttons. but seems to lag out the sro.exe that its running in.

Edited by oddysey
Link to comment
Share on other sites

In your main-loop you're just calling the fight-function and within that function there's some actions done

if PixelSearch find the specified color... One of these are a Sleep which avoids the CPU-usage to go up to

around 100%. So if PixelSearch doesn't find the color nothing will be done, the script gets no "sleep", the

function will end and AutoIt will step back to the loop again. Here fight() is called again and so it continues.

What happens if the color isn't found for a longer period of time ? The script doesn't get any "sleep", the

CPU-usage goes up which makes your computer lag. So, how to fix this ? Well, just put in a Sleep some

place when the color isn't found... for example like I've done in the modified code below... Btw, I did some

small rearranging of the code to make it a bit more logically structured...

Global $Paused

Sleep(2000)
WinActivate("SRO_Client")
Sleep(2000)

HotKeySet("z", "Pause")

While 1 = 1
    fight()
WEnd

Func Pause()
    $Paused = Not $Paused
    While $Paused
        Sleep(400)
    WEnd
EndFunc   ;==>Pause

Func fight()
    $coord = PixelSearch(100, 100, 900, 525, 0xa00a00, 1, 2)
    If Not @error Then
        MouseMove($coord[0], $coord[1], 0)
        Sleep(100)
        MouseClick("left", $coord[0], $coord[1])
        Sleep(500)
        If (PixelGetColor(429, 21) = 0x2C89CB) Then
            Send("1")
            Send("2")
        EndIf
    Else
        Sleep(10) ; for example like this...adjust the ms to your needs
    EndIf
    ;send ("{left 6}")
EndFunc   ;==>fight
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...