Jump to content

Recommended Posts

Posted

okay first of all, i like to say "hi", and greetings to the creater of autoit, its a really cool program

no to my script i planing to make.

its a gaming script so i need to start it with a hotkey, than it needs to perform an action every 180sec (more/less)

and during this time it needs to just send a few "keycommands".

okay this is what i have so far

Global $key

HotkeySet ("{F9}", "Start")

HotkeySet ("{F8}", "Stop")

;HotkeySet ("{F7}", "Def")

$x = 0

While 1

Sleep (100)

WEnd

Func Start()

If WinExists ("Do") Then

WinActivate ("Do")

Def()

Endif

EndFunc

Func Def() ; this function needs to be performed every 180sec

WinActivate ("Do")

send ("2")

Atk()

EndFunc

Func Atk() ; and this function every 10sec

WinActivate ("Do")

send ("t")

sleep (1000)

send ("a")

sleep ("10000")

send ("1")

send ("1")

EndFunc

Func Stop()

MsgBox(4096, "Stop", "Script stopped!", 2)

Exit

EndFunc

so i need some kind of a loop that just performs def() every 180sec and atk() every 10sec, time started from the first perform of def().

my problem is the "time" i have no clou how to count in realtime, i know that i can count with variables like $x = 1

$x + 1 = 2 ... so on

so it would be kind if somebody could help me with this ;)

thanx a lot

  • Moderators
Posted

For time options you can look at TimerInit()/TimerDiff() ... It's calculated in Milliseconds, so to get the difference in seconds it would be TimerDiff($var) / 1000.

You can also take a look at AdlibEnable(), as that will break from the current function at a set millisecond time, and do whatever function you sent it to.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

thx now it works, but now i have another problem

thats the script:

Global $key

HotkeySet ("{F9}", "Start")

HotkeySet ("{F8}", "Stop")

;HotkeySet ("{F7}", "pause")

$x = 0

$begin = 0

$def = 0

While 1

Sleep (100)

WEnd

Func Start()

If WinExists ("Do") Then

WinActivate ("Do")

def()

Endif

EndFunc

Func def()

WinActivate ("Do")

send ("22")

sleep (5000)

$begin = TimerInit()

send ("1")

atk()

EndFunc

Func atk()

WinActivate ("Do")

send ("t")

sleep (2000)

send ("aaa")

sleep (6000)

send ("111")

sleep (1000)

send ("111")

wait()

EndFunc

Func wait()

$dif = TimerDiff($begin)

if $dif > 95000 Then

def()

Elseif $dif < 95000 Then

atk()

Endif

EndFunc

Func Stop()

send ("{Enter}")

sleep ("1000")

send (".")

;MsgBox(4096, "Stop", "Script gestoppt!", 2)

Exit

EndFunc

the problem is, that when the program runs for a certain time i get a error msg "that the limit of recursion has been exeded" or something like this... any idea how i can get rid of this? so that the programm will runs dan runs and runs ^^

  • Developers
Posted (edited)

You are not letting Func(s) end.,

Start() calls Def()

Def() calls atk()

atk() calls wait()

wait(0 calls def() or atk() <== start of the recursion

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

so what do i have to do excatly?

here is the errormsg again:

C:\.....au3 (46) : ==>

Recursion level has been exceeded - AutoIt will quit to prevent stack

overflow.:

atk()

  • Developers
Posted (edited)

so what do i have to do excatly?

Learn how to program ?... ;)

Rethink your logic and let a FUNC...ENDFUNC finish in stead of always calling another FUNC.

When a FUNC ends it will return to the spot it was called from.

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

oh man... can i have another clou ...

i testet this but not working

Func atk()
    WinActivate ("Do")
    send ("t")
    sleep (2000)
    send ("aaa")
    sleep (6000)
    send ("111")
    sleep (1000)
    send ("111")
    wait()
EndFunc

Func wait()
    $dif = TimerDiff($begin)
    if $dif > 95000 Then 
    def()
;Elseif $dif < 95000 Then 
;   atk()
Endif
EndFunc

than in wait() it should return to atk() right?

but thats not the case... dont know where it goes... but not to atk()...

  • Developers
Posted

oh man... can i have another clou ...

Isn't this really what you want ?

Global $key
HotKeySet("{F9}", "Start")
HotKeySet("{F8}", "Stop")
;HotkeySet ("{F7}", "pause")

$x = 0
$begin = 0
$def = 0
While 1
    Sleep(100)
WEnd

Func Start()
    If WinExists("Do") Then
        WinActivate("Do")
        Send("22")
        Sleep(5000)
        $begin = TimerInit()
        Send("1")
        While 1
            WinActivate("Do")
            Send("t")
            Sleep(2000)
            Send("aaa")
            Sleep(6000)
            Send("111")
            Sleep(1000)
            Send("111")
            $dif = TimerDiff($begin)
            If $dif > 95000 Then Return
        WEnd
    EndIf
EndFunc   ;==>Start

Func Stop()
    Send("{Enter}")
    Sleep("1000")
    Send(".")
    ;MsgBox(4096, "Stop", "Script gestoppt!", 2)
    Exit
EndFunc   ;==>Stop

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

thx a lot,

a few questions

this line "If $dif > 95000 Then Return" the return points to where?

the problem is that the while loop doesn seems to work right, well i try a bit

okay i tested this

Func Start()
    If WinExists("Do") Then
        WinActivate("Do")
        Send("22")
        Sleep(5000)
        $begin = TimerInit()
        Send("1")
        $dif = TimerDiff($begin)
        While $dif < 95000;1
            WinActivate("Do")
            Send("t")
            Sleep(2000)
            Send("aaa")
            Sleep(6000)
            Send("111")
            Sleep(1000)
            Send("111")
            $dif = TimerDiff($begin)
           ;If $dif > 95000 Then Return
        WEnd
    EndIf
EndFunc

this works a few times, but after a few loops the script does nothing

Edited by darkjoscha
Posted

okay the prolbem was, that after $dif < 95000 is right the script wont go again to func start()

so i added the start() again at the end of the func start(). so it works, but the question now ist for how long...

next task for me is to build a pause hotkey into it i give my best^^

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