gamepin126 Posted July 12, 2007 Share Posted July 12, 2007 (edited) I have no idea what I did wrong, or how to fix this. Help will be appreciated HotKeySet("{DOWN}", "Toggle") $toggle = 0 While 1 If WinActive("SRO_Client") Then If $toggle = 1 Then Send("1",1) EndIf EndIf Sleep(2000) WEnd Func Toggle() If WinActive("SRO_Client") Then If $toggle = 0 Then $toggle = 1 ToolTip("1", 0, 0) Else $toggle = 0 ToolTip("0", 0, 0) EndIf Else Send("{DOWN}") EndIf EndFunc CODE>"C:\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:\Documents and Settings\****\My Documents\Scripts\Silkroad\Silkroad AutoAttack.au3" /autoit3dir "C:\AutoIt3\beta" /UserParams +>09:52:46 Starting AutoIt3Wrapper v.1.9.2 >Running AU3Check (1.54.3.0) from:C:\AutoIt3\beta +>09:52:46 AU3Check ended.rc:0 >Running:(3.1.1.133):C:\AutoIt3\beta\autoit3.exe "C:\Documents and Settings\****\My Documents\Scripts\Silkroad\Silkroad AutoAttack.au3" C:\Documents and Settings\Rawr\My Documents\Scripts\Silkroad\Silkroad AutoAttack.au3 (24) : ==> Recursion level has been exceeded - AutoIt will quit to prevent stack overflow.: Send("{DOWN}") +>09:52:52 AutoIT3.exe ended.rc:0 +>09:52:52 AutoIt3Wrapper Finished >Exit code: 0 Time: 6.653 It works fine up until I focus another window, and press down. It then crashes. Edited July 12, 2007 by gamepin126 Link to comment Share on other sites More sharing options...
mikehunt114 Posted July 12, 2007 Share Posted July 12, 2007 (edited) Toggle() is effectively calling itself as soon as you activate another window. You'll have to restructure your code to avoid recursion. Edited July 12, 2007 by mikehunt114 IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 12, 2007 Moderators Share Posted July 12, 2007 Else HotKeySet('{DOWN}') Send("{DOWN}") HotKeySet('{DOWN}', 'Toggle') EndIfJust turn the hotkey off before you use Send() 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. Link to comment Share on other sites More sharing options...
gamepin126 Posted July 12, 2007 Author Share Posted July 12, 2007 Else HotKeySet('{DOWN}') Send("{DOWN}") HotKeySet('{DOWN}', 'Toggle') EndIfJust turn the hotkey off before you use Send() That works, thanks a lot. But why does it do this? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 12, 2007 Moderators Share Posted July 12, 2007 That works, thanks a lot. But why does it do this?Well, you set the hotkey {down} ... then you Send {down} that means the hotkey is set again and repeats the function, obviously the condition isn't true, so it keeps doing it over and over, until you've done it 384 times and you get the recursion issue. I usually use a _HotKeySend() function when I need to send something so I don't have to keep writing HotKeySet(Key)/Send()/HotKeySet(key,function) all the time. Example:Global $sToggle = 'Toggle' HotKeySet("{DOWN}", $sToggle) $toggle = 0 While 1 If WinActive("SRO_Client") Then If $toggle = 1 Then Send("1",1) EndIf EndIf Sleep(2000) WEnd Func Toggle() If WinActive("Untitled - Notepad") Then If $toggle = 0 Then $toggle = 1 ToolTip("1", 0, 0) Else $toggle = 0 ToolTip("0", 0, 0) EndIf Else _HotKeySend('{DOWN}', '{DOWN}', $sToggle) EndIf EndFunc Func _HotKeySend($sSend, $sHotKey, $sFunction) HotKeySet($sHotKey) Send($sSend) Return HotKeySet($sHotKey, $sFunction) EndFunc 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. Link to comment Share on other sites More sharing options...
mikehunt114 Posted July 12, 2007 Share Posted July 12, 2007 Pressing "DOWN" calls the function Toggle()...which presses "DOWN"...which calls Toggle()...which presses "DOWN"....see where I'm going? Calling a function within itself creates an infinite loop, which eats up your computer's memory. AutoIt has a recursion level limit to prevent you from consuming all your computer's memory and crashing your puter. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
gamepin126 Posted July 12, 2007 Author Share Posted July 12, 2007 (edited) Very nice, thanks a lot mike and Sm0ke_N for explaining it Edited July 12, 2007 by gamepin126 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now