J0ker Posted January 22, 2007 Share Posted January 22, 2007 (edited) Ok, I'm having problem with a certain part of my script. It has been made to protect the script to stuck, it's an anti-stuck function. A function is called every 6000ms to check if the mouse isnt moving. If the test succeed 10 time in a row, that mean that the script is stuck, then the script restart. I'm having one problem:1. If the test suceed and the function Start() is called, the AdlibEnable stop to work and I dont know why. expandcollapse popup;Variables Global $Paused, $pos, $Timestack ; If the Mouse is stuck, Restart the script AdlibEnable("ScriptStuck", 6000) While 1 $pos = MouseGetPos() Sleep(500) WEnd Func ScriptStuck() ToolTip("Time: " & $Timestack,0,13) Local $var_2 = MouseGetPos() If IsArray($var_2) And IsArray($pos) Then If $Timestack = 10 Then $Timestack = 0 Start() ElseIf $pos[0] = $var_2[0] And $pos[1] = $var_2[1] Then $Timestack = $Timestack + 1 Else $pos = $var_2 $Timestack = 0 EndIf EndIf EndFunc ; Func Start() ;blabla Main() EndFunc Func Main() While 1 sleep(100) While ;blabla EndFunc oÝ÷ Økçm¢Zqëaxe±'i¹^ªê-IÊâ¦Ô¹É*ºzÓM"ÈzØ^1¨§¶§¶µªí~éܶ*'në[¢Ø]¡ë'· +eiÇjëh×6 ToolTip("Time: " & $Timestack,0,13) in the function to see if the function was working or not. It's how I know that it work well but when the func start() is called, Func ScriptStuck doesnt work anymore. Edited January 23, 2007 by J0ker Link to comment Share on other sites More sharing options...
BrettF Posted January 22, 2007 Share Posted January 22, 2007 (edited) You've got 2 whiles While 1 $pos = MouseGetPos() Sleep(500) WEnd ; Wait until ENTER is pressed to start the script While 1 ; This should be before the AntiStuck script but If I place it before, it doesnt work sleep(100) Wend Just noticed it Would it make a difference?? Edited January 22, 2007 by bert Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
BrettF Posted January 22, 2007 Share Posted January 22, 2007 Works for me: expandcollapse popup;Hotkeys HotKeySet("{ENTER}", "Start") ; Run the script when ENTER is pressed ;Variables Global $Paused, $pos, $Timestack ; If the Mouse is stuck, Restart the script AdlibEnable("ScriptStuck", 6000) While 1 $pos = MouseGetPos() Sleep(500) WEnd Func Start() EndFunc Func Main() ; EndFunc Func ScriptStuck() ToolTip("Time: " & $Timestack,0,13) Local $var_2 = MouseGetPos() If IsArray($var_2) And IsArray($pos) Then If $Timestack = 10 Then $Timestack = 0 Start() ElseIf $pos[0] = $var_2[0] And $pos[1] = $var_2[1] Then $Timestack = $Timestack + 1 Else $pos = $var_2 $Timestack = 0 EndIf EndIf EndFunc ; Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
J0ker Posted January 22, 2007 Author Share Posted January 22, 2007 @Bert : your script doesnt work for me. I tried this and it's not working AdlibEnable("ScriptStuck", 6000) While 1 $pos = MouseGetPos() Sleep(100) WEnd Func ScriptStuck() ToolTip("Time: " & $Timestack,0,13) Local $var_2 = MouseGetPos() If IsArray($var_2) And IsArray($pos) Then If $Timestack = 5 Then $Timestack = 0 AdlibDisable() AdlibEnable("ScriptStuck", 6000) Start() ElseIf ($pos[0] = $var_2[0]) And ($pos[1] = $var_2[1]) Then $Timestack = $Timestack + 1 Else $pos = $var_2 $Timestack = 0 EndIf EndIf EndFunc ; Why when the function call Start(), the AdlidEnabe stop to work? Link to comment Share on other sites More sharing options...
BrettF Posted January 22, 2007 Share Posted January 22, 2007 So you want Start () to be run if the test to see if the mouse has not moved in (whatever the time was...) and if enter was pressed you want Start () to be called? Is that right?? cause now im confusing myself Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
J0ker Posted January 22, 2007 Author Share Posted January 22, 2007 The Enter key doesnt change anything, I just wanted to know why when a function is called from inside an AdlildEnable, the AdlidEnable stop to work? How can I correct this? Link to comment Share on other sites More sharing options...
BrettF Posted January 22, 2007 Share Posted January 22, 2007 The Enter key doesnt change anything, I just wanted to know why when a function is called from inside an AdlildEnable, the AdlidEnable stop to work? How can I correct this? I dont know...... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
J0ker Posted January 22, 2007 Author Share Posted January 22, 2007 (edited) The Enter key doesnt change anything, I just wanted to know why when a function is called from inside an AdlildEnable, the AdlidEnable stop to work? How can I correct this?Does anyone know why? Edited January 22, 2007 by J0ker Link to comment Share on other sites More sharing options...
Valuater Posted January 22, 2007 Share Posted January 22, 2007 this works for me expandcollapse popup;Variables Global $Paused, $pos, $Timestack ; If the Mouse is stuck, Restart the script AdlibEnable("ScriptStuck", 6000) While 1 $pos = MouseGetPos() Sleep(500) WEnd Func ScriptStuck() ToolTip("Time: " & $Timestack,0,13) Local $var_2 = MouseGetPos() If IsArray($var_2) And IsArray($pos) Then If $Timestack = 10 Then $Timestack = 0 Start() ElseIf $pos[0] = $var_2[0] And $pos[1] = $var_2[1] Then $Timestack = $Timestack + 1 Else $pos = $var_2 $Timestack = 0 EndIf EndIf EndFunc ; Func Start() ToolTip("Time: " & $Timestack,0,13, "Start") EndFunc Func Main() ToolTip("Time: " & $Timestack,0,13, "Main") EndFunc 8) Link to comment Share on other sites More sharing options...
J0ker Posted January 22, 2007 Author Share Posted January 22, 2007 (edited) Valuater : I just putted ToolTip("Time: " & $Timestack,0,13) to see if the the Function ScriptStuck() was working, it's not part of my script. Maybe I explained wrong my problem:I have a long script. I made the Adlilenable to prevent the script to eventual bugs. It runs as an external function while my main script is looping. If there's a delay and the script stuck, the function ScriptStuck will act as an AntiStuck. The problem in my script is that the AdlidEnable work fine until the script is stuck for the first time and $TimeStack = 10 so the function Start() is called.In short, it work only one time then then AdlidEnable stop to work. I want to find a way to correct that. Why the AdildEnable work only one time?EDIT: If I run this little script alone, it work but If I run it in my real script ( there's a loop in the Main function) it work only one time. Edited January 22, 2007 by J0ker Link to comment Share on other sites More sharing options...
Valuater Posted January 22, 2007 Share Posted January 22, 2007 Valuater : I just putted ToolTip("Time: " & $Timestack,0,13) to see if the the Function ScriptStuck() was working, it's not part of my script. Maybe I explained wrong my problem:I have a long script. I made the Adlilenable to prevent the script to eventual bugs. It runs as an external function while my main script is looping. If there's a delay and the script stuck, the function ScriptStuck will act as an AntiStuck. The problem in my script is that the AdlidEnable work fine until the script is stuck for the first time and $TimeStack = 10 so the function Start() is called.In short, it work only one time then then AdlidEnable stop to work. I want to find a way to correct that. Why the AdildEnable work only one time?EDIT: If I run this little script alone, it work but If I run it in my real script ( there's a loop in the Main function) it work only one time.I am telling you that this test script you posted (with the 1 tooltip addition i made) is still running on my computer and still working... there is no problem with this script continueing the AdlibEnable() Function8) Link to comment Share on other sites More sharing options...
J0ker Posted January 22, 2007 Author Share Posted January 22, 2007 (edited) I forgot to add something to the script I posted here. expandcollapse popup;Variables Global $Paused, $pos, $Timestack ; If the Mouse is stuck, Restart the script AdlibEnable("ScriptStuck", 6000) While 1 $pos = MouseGetPos() Sleep(500) WEnd Func ScriptStuck() ToolTip("Time: " & $Timestack,0,13) Local $var_2 = MouseGetPos() If IsArray($var_2) And IsArray($pos) Then If $Timestack = 10 Then $Timestack = 0 Start() ElseIf $pos[0] = $var_2[0] And $pos[1] = $var_2[1] Then $Timestack = $Timestack + 1 Else $pos = $var_2 $Timestack = 0 EndIf EndIf EndFunc ; Func Start() Main() EndFunc Func Main() EndFunc The function start() call the function Main(). Edited January 23, 2007 by J0ker Link to comment Share on other sites More sharing options...
Valuater Posted January 22, 2007 Share Posted January 22, 2007 works.... expandcollapse popup;Variables Global $Paused, $pos, $Timestack, $xtimes ; If the Mouse is stuck, Restart the script AdlibEnable("ScriptStuck", 6000) While 1 $pos = MouseGetPos() Sleep(500) WEnd Func ScriptStuck() ToolTip("Time: " & $Timestack, 0, 13) Local $var_2 = MouseGetPos() If IsArray($var_2) And IsArray($pos) Then If $Timestack = 10 Then $Timestack = 0 Start() ElseIf $pos[0] = $var_2[0] And $pos[1] = $var_2[1] Then $Timestack = $Timestack + 1 Else $pos = $var_2 $Timestack = 0 EndIf EndIf EndFunc ;==>ScriptStuck Func Start() Main() EndFunc ;==>Start Func Main() $xtimes += 1 MsgBox(0x0, "test", $xtimes, 2) EndFunc ;==>Main 8) Link to comment Share on other sites More sharing options...
J0ker Posted January 23, 2007 Author Share Posted January 23, 2007 (edited) Yay, I found out where my problem came from. I'm sure that it's because of the while 1. I need to correct the problem now that I know that it came from there.expandcollapse popupHotKeySet("{ENTER}", "Start") ; Run the script when ENTER is pressed ;Variables Global $Paused, $pos, $Timestack ; If the Mouse is stuck, Restart the script AdlibEnable("ScriptStuck", 6000) While 1 $pos = MouseGetPos() Sleep(500) WEnd Func ScriptStuck() ToolTip("Time: " & $Timestack, 0, 13) Local $var_2 = MouseGetPos() If IsArray($var_2) And IsArray($pos) Then If $Timestack = 10 Then $Timestack = 0 Start() ElseIf $pos[0] = $var_2[0] And $pos[1] = $var_2[1] Then $Timestack = $Timestack + 1 Else $pos = $var_2 $Timestack = 0 EndIf EndIf EndFunc ;==>ScriptStuck Func Start() MouseClick ( "left" , 525, 270 , 1 , 3 ) sleep(500) Main() EndFunc ;==>Start Func Main() MouseClick ( "left" , 525, 215 , 1 , 3 ) While 1 ; Problem came from here sleep(100) Wend EndFunc ;==>MainI added a loop to this script and the Adlidenable work only one time like in my real script. Edited January 23, 2007 by J0ker Link to comment Share on other sites More sharing options...
CoderDunn Posted January 23, 2007 Share Posted January 23, 2007 (edited) The problem is ... I think adlib wont run again until that last function it called is done running. It's set up like this: AdlibEnable() calls ... ---------------------------ScriptStuck(), it called ... ---------------------------------------------------------Start() which called ... ---------------------------------------------------------------------------------------Main() So ... Adlib wont call ScriptStuck again until the func Main() is done, which alows Start() to finish, which allows ScriptStuck() to finish, which at the end lets Adlib finish. So instead of using AdlibEnable, have the check in your Main() func loop with TimerInit() and TimerDiff() Edited January 23, 2007 by Hallman Link to comment Share on other sites More sharing options...
J0ker Posted January 23, 2007 Author Share Posted January 23, 2007 (edited) I understand what your saying Hallman but why did it work the first time and not the other time? The Scriptstuck function need to be external because this function protect my script to stuck. I cant implant it at a certain point in my loop. Edited January 23, 2007 by J0ker Link to comment Share on other sites More sharing options...
CoderDunn Posted January 23, 2007 Share Posted January 23, 2007 (edited) Here I fixed it for you It worked in the first example, because the was no loop to keep the fucntion running. So, Adlibs function ended. expandcollapse popupHotKeySet("{ENTER}", "HotkeyStart") ; Run the script when ENTER is pressed Global $Script_Start = 0 ;Variables Global $Paused, $pos, $Timestack ; If the Mouse is stuck, Restart the script While 1 If $Script_Start = 1 Then Start() WEnd Func HotkeyStart() If $Script_Start = 0 Then $Script_Start = 1 Else $Script_Start = 0 EndIf EndFunc ;==>HotkeyStart Func Start() TrayTip("Test", "Script Started ...", 3) MouseClick("left", 525, 270, 1, 3) Sleep(500) Main() EndFunc ;==>Start Func Main() MouseClick("left", 525, 215, 1, 3) $MainTimer = TimerInit() ; timer which waits for the 600 m/s mark. $Base_Mouse_Coordinates = MouseGetPos() ; get the origional coordinates While 1 ; Problem came from here $Current_Mouse = MouseGetPos() ; get new coordinates If $Base_Mouse_Coordinates[0] <> $Current_Mouse[0] And $Base_Mouse_Coordinates[1] <> $Current_Mouse[1] Then ; If mouse has moved, reset check $MainTimer = TimerInit() $Base_Mouse_Coordinates = MouseGetPos() EndIf If TimerDiff($MainTimer) > 6000 Then Return 0 ; If the mouse wasn't moved for 6 secs, end func Sleep(100) WEnd EndFunc ;==>Main Hallman EDIT: Code error. It's correct now Edited January 23, 2007 by Hallman Link to comment Share on other sites More sharing options...
J0ker Posted January 23, 2007 Author Share Posted January 23, 2007 (edited) Ok I will test this, but does this will do the same thing that Adlid was doing? because if not, it wont work for my script. It need to be external as I said cause the script can stuck anytime in my loop ( my loop is over 350 lines of code) Edited January 23, 2007 by J0ker Link to comment Share on other sites More sharing options...
CoderDunn Posted January 23, 2007 Share Posted January 23, 2007 (edited) Well this is gonna be difficult. Hopfully you can come up with something based on my example. If it comes down to it, you can always have the script restart itself to solve the adlib problem. Well I gotta get off the internet. Dial up takes up phone line and my mom hates it Edited January 23, 2007 by Hallman Link to comment Share on other sites More sharing options...
J0ker Posted January 23, 2007 Author Share Posted January 23, 2007 (edited) Thanks for your help hallman but your code wont work with my script. I need to find a way to work around my problem using my basic code. expandcollapse popupHotKeySet("{ENTER}", "Start") ; Run the script when ENTER is pressed ;Variables Global $Paused, $pos, $Timestack ; If the Mouse is stuck, Restart the script AdlibEnable("ScriptStuck", 6000) While 1 $pos = MouseGetPos() Sleep(500) WEnd Func ScriptStuck() ToolTip("Time: " & $Timestack, 0, 13) Local $var_2 = MouseGetPos() If IsArray($var_2) And IsArray($pos) Then If $Timestack = 10 Then $Timestack = 0 Start() ElseIf $pos[0] = $var_2[0] And $pos[1] = $var_2[1] Then $Timestack = $Timestack + 1 Else $pos = $var_2 $Timestack = 0 EndIf EndIf EndFunc ;==>ScriptStuck Func Start() MouseClick ( "left" , 525, 270 , 1 , 3 ) sleep(500) Main() EndFunc ;==>Start Func Main() MouseClick ( "left" , 525, 215 , 1 , 3 ) While 1 ; ######### Problem come from here ########## sleep(100) Wend EndFunc ;==>Main Edited January 23, 2007 by J0ker 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