cesars77 Posted April 12, 2011 Share Posted April 12, 2011 (edited) I'm trying to use TimerInit/TimerDiff inside a function once the function is called but i can't understand why they are completly ignored.... Curiously, my script is continuing to execute without any errors... I would appreciate if anyone can tell me what's wrong or what i'm doing wrong...Why TimerInit/TimerDiff are ignored?? Thx! Func WaitDelay() If ValuesScreen() = 1 Then $begin__ = TimerInit() while ScreenCheck("MainValuesScreen") = 0 Sleep(1000) wend EndIf $Loop = $Loop + $ATTEMPTS $JOINATTEMPTS = 0 If $Loop >= $BeforeSwitch AND $Count > 0 Then Sleep(1000+($Delay*1000)) If (TimerDiff($begin__) * 1000 ) < $Duration Then Sleep ( $Duration - (TimerDiff($begin__) * 1000 )) Endif Else Sleep(5000+($Delay*1000)) If (TimerDiff($begin__) * 1000 ) < $Duration Then Sleep ( Duration - (TimerDiff($begin__) * 1000 )) Endif EndIf EndFunc Edited April 12, 2011 by cesars77 Link to comment Share on other sites More sharing options...
bogQ Posted April 12, 2011 Share Posted April 12, 2011 (edited) Try to post shorter version of script that can replicate problem. Edited April 12, 2011 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 12, 2011 Moderators Share Posted April 12, 2011 cesars77,It is difficult to tell from that incomplete, syntactically flawed snippet - but I would hazard a guess at one of the following:- 1. You are having problems because you only ever set the $begin__ variable if you enter the first loop. If you do not enter the loop, the variable is not set and so TimerDiff has nothing to work on. - 2. You are multiplying the TimerDiff return by 1000 - I would have expected a division by 1000 to get seconds. As it stands you are very likely to be setting Sleep to a negative value (as the TimerDiff return will already be in the thousands) - which means the Sleep function does not "sleep" at all. Sleep(1000) ConsoleWrite("fred" & @CRLF) Sleep(-5000) ConsoleWrite("another instantaneous fred" & @CRLF)As a general rule, if you want help it is best to provide a working script that illustrates the problem rather than a few lines which make little sense to to someone unfamiliar with the overall script. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
cesars77 Posted April 12, 2011 Author Share Posted April 12, 2011 (edited) Well, i suspected that my "syntactically flawed snippet" explanations wouldn't be enough "explicit" but i can really disclose more because it will be a private script who will be used by a little engineering office...I'm not supposed to even disclose a part of the script but i've to admit that i'm lost here.. I can disclosed the whole func but not the whole script... Btw, i changed the multiplication by a division but the "if TimerDiff" is still being ignored... Func Start() While 1 For $Count = 1 To 3 $Loop = $Loop + 1 If ValuesScreen() = 1 Then $begin__ = TimerInit() while ScreenCheck("MainValuesScreen") = 0 Sleep(1000) wend $Loop = $Loop + $ATTEMPTS $ATTEMPTS = 0 If $Loop >= $BeforeSwitch AND $Count > 0 Then Sleep(1000+($Delay*1000)) if (TimerDiff($begin__) / 1000 ) < $Duration Then Sleep ( $Duration - (TimerDiff($begin__) / 1000 )) endif Else Sleep(5000+($Delay*1000)) if (TimerDiff($begin__) / 1000 ) < $Duration Then Sleep ( $Duration - (TimerDiff($begin__) / 1000 )) ;~ endif EndIf Else $Loop = 0 opt("SendKeyDelay", 5) KillWin() if $Count > 0 Then SetNext() endif EndIf Next WEnd EndFunc Edited April 12, 2011 by cesars77 Link to comment Share on other sites More sharing options...
MvGulik Posted April 12, 2011 Share Posted April 12, 2011 (edited) @#1: + http://www.autoitscript.com/wiki/FAQ#How_can_I_debug_my_script.3F@#3: (Hue: If Loop ?) Edited April 12, 2011 by singularity "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
MvGulik Posted April 12, 2011 Share Posted April 12, 2011 I can disclosed the whole func but not the whole script... Nobody asked for your whole script. "a working script that illustrates the problem" was the suggestion. "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
cesars77 Posted April 12, 2011 Author Share Posted April 12, 2011 (edited) @#1: + http://www.autoitscript.com/wiki/FAQ#How_can_I_debug_my_script.3F @#3: (Hue: If Loop ?) @#-1Redirect me to the FAQ is useless when i don't even know what's wrong... @#2 Yeah If $Loop>=....is there a problem in my syntax? i can't see... to be more clear, here is the ignored lines... if (TimerDiff($begin__) / 1000 ) < $Duration Then Sleep ( $Duration - (TimerDiff($begin__) / 1000 )) endif And i can't really replicate the problem in a shorter script.. Edited April 13, 2011 by cesars77 Link to comment Share on other sites More sharing options...
MvGulik Posted April 12, 2011 Share Posted April 12, 2011 (edited) @#-1Redirect me to the FAQ is useless when i don't even know what's wrong...If you don't even take a look at it the part I linked up, your right, its useless.If you ever decide you like to learn how to be able to do basic code debugging yourself. Revisit that part.@#2 Yeah If $Loop>=....is there a problem in my syntax? i can't see...Translation for "@#3" is "At Message number 3"The related problem (as noted by Melba) is that you dropped a generally vital variable declaration+data assignment behind a Conditional statement.And i can really replicate the problem in a shorter script..Good. So why not post that to?--- --- ---After taking a quick look at your code in #4.Do yourself a favor, and give Scite4AutoIt3 at try. Edited April 13, 2011 by singularity "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
cesars77 Posted April 13, 2011 Author Share Posted April 13, 2011 (edited) Good. So why not post that to? --- --- --- After taking a quick look at your code in #4. Do yourself a favor, and give Scite4AutoIt3 at try. Sorry, i meant "i CAN'T" really replicate the problem in a shorter script.. And btw, i'm using Scite4AutoIt3...Do you think i build a script with Notepad??? And when i do a SyntaxCheck no error or even a warning comes out... i'm not a programmer, so i do not understand all the complexities of a .au3 script, and i don't really need too....I'd appreciate if you could tell me exactly what to do... Edited April 13, 2011 by cesars77 Link to comment Share on other sites More sharing options...
IAmTheManYo Posted April 13, 2011 Share Posted April 13, 2011 Since the script ran and simply ignored the TimerInit/TimerDiff, I strongly doubt it's a syntax error. Remember, just because the code doesn't look like your code, doesn't mean it's a syntax error. A simple mistake in variables or loops is most likely the issue, so let's put the syntax bashing aside. Cesar, even if you cannot post the code, I think simple remarks to the scripts telling us what your custom functions do, and what you expect certain parts of the script to do would help. Another handy trick is to place MsgBox's throughout the function, to see if the script is reaching certain parts of the script that you want it to. This way you can find out exactly where in the script you may be having an issue. There may be an easier way to do this, but MsgBox's have never failed me when attempting to find a bad section of code. So your first steps since you cannot post the entire code should be, 1) Remark the hell out of what you can show us, 2) Use MsgBox's to find what section of code isn't working as you would like. Add variable values to the MsgBox's and etc, to see if those variables are matching what they should be at that point of the code, then move on till you find what isn't working right. Link to comment Share on other sites More sharing options...
MvGulik Posted April 13, 2011 Share Posted April 13, 2011 <snip*x> I'd appreciate if you could tell me exactly what to do...Provide the relative code that's responsible for the state and behavior of the variable's $BeforeSwitch and $Count.If $Loop >= $BeforeSwitch And $Count > 0 Then (and ... any other code that might effect those parts, etc, etc)Or learn how to print those variables state/behavior while test running your script so you can (try to) see whats going on in your code, and possible fix it yourself. (or to provide that information in your help request.) Ergo:@#1: + http://www.autoitscript.com/wiki/FAQ#How_can_I_debug_my_script.3FAnother handy trick is to place MsgBox's throughout the function, to see if the script is reaching certain parts of the script that you want it to. This way you can find out exactly where in the script you may be having an issue. GL. @IAmTheManYo: OP is all yours. (freeee, free at last.) "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
cesars77 Posted April 13, 2011 Author Share Posted April 13, 2011 Thx guys for all your tips. By using MsgBox, i've finally found what's going wrong...I discovered that the algorythm of the sleep delay isn't properly formulated... Sleep ( $Duration - (TimerDiff($begin__) / 1000 )) I had to remember that the "$Duration" value who is retriened from an .ini file and is IN SECOND!!!!! And forgot that Sleep function is in MILLISECOND.(2X ) Well, even if I'm not dumb in mathematic, I can not find the right algorithm... I finally tought at...(convert $Duration in ms) Sleep ( ($Duration * 1000 ) - TimerDiff($begin__)) I tested that new algorythm but the Sleep delay is still not properly executed... Tell me if i'm wrong, but logically, that algorythm should return a Sleep delay in ms??? anyone can tell me what's wrong now?? Thx! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 13, 2011 Moderators Share Posted April 13, 2011 cesars77,Looks like one of my suggestions was valid. Perhaps you could try the other and use MsgBox or ConsoleWrite to see what value you get from ($Duration * 1000 ) - TimerDiff($begin__) - if it is negative you get no sleep as the script I posted earlier showed. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrewManNH Posted April 13, 2011 Share Posted April 13, 2011 What's wrong is that you're code isn't clear as to what exactly it is you're trying to achieve with the sleep command. Try putting a COMPLETE, WORKING script that demonstrates EXACTLY what it is you're seeing and explain exactly what it is you expect it to do that it's not. This way we can see where the flaws are and help you with them. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
cesars77 Posted April 13, 2011 Author Share Posted April 13, 2011 What's wrong is that you're code isn't clear as to what exactly it is you're trying to achieve with the sleep command. Try putting a COMPLETE, WORKING script that demonstrates EXACTLY what it is you're seeing and explain exactly what it is you expect it to do that it's not. This way we can see where the flaws are and help you with them. Did you read from the first post?? cesars77, Looks like one of my suggestions was valid. Perhaps you could try the other and use MsgBox or ConsoleWrite to see what value you get from ($Duration * 1000 ) - TimerDiff($begin__) - if it is negative you get no sleep as the script I posted earlier showed. M23 yeah it Look like one of your suggestions was valid. I retrieved the value of ($Duration * 1000 ) - TimerDiff($begin__) who gave a positive value...But again sleep delay is still not properly executed... I've finally found the right algotrythm!!!!!!!! It's completly illogical but curiously it works. Sleep ($Duration * 1000 ) - TimerDiff($begin__)/1000 If anyone can explain that, i'd appreciate... thx guy for the help! Really appreciated. C. Link to comment Share on other sites More sharing options...
MrMitchell Posted April 13, 2011 Share Posted April 13, 2011 I've finally found the right algotrythm!!!!!!!! It's completly illogical but curiously it works. Sleep ($Duration * 1000 ) - TimerDiff($begin__)/1000 If anyone can explain that, i'd appreciate... thx guy for the help! Really appreciated. C. What's your expected result from TimerDiff($begin__)/1000 ? TimerDiff returns milliseconds, then you're dividing that by 1000 which yields an even smaller number. Then that result is being subtracted from Sleep ($duration * 1000) which will always (I think) evaluate to 1. So you have 1 minus probably a really small number and your result is going to always going to be slightly less than 1. Or am I reading this wrong? LoL from the looks of this whole thread and based on my past posts I wouldn't be surprised if I'm completely lost here. Link to comment Share on other sites More sharing options...
cesars77 Posted April 13, 2011 Author Share Posted April 13, 2011 (edited) What's your expected result from TimerDiff($begin__)/1000 ? TimerDiff returns milliseconds, then you're dividing that by 1000 which yields an even smaller number. Then that result is being subtracted from Sleep ($duration * 1000) which will always (I think) evaluate to 1. So you have 1 minus probably a really small number and your result is going to always going to be slightly less than 1.Or am I reading this wrong? LoL from the looks of this whole thread and based on my past posts I wouldn't be surprised if I'm completely lost here.like me,your'e lost... Edited April 13, 2011 by cesars77 Link to comment Share on other sites More sharing options...
MrMitchell Posted April 13, 2011 Share Posted April 13, 2011 like me,your'e lost...I figured I couldn't make things any worse lol. So were you going to answer my question? Or anyone's for that matter? BTW: What's in your script that can't easily be masked to protect the security of your office? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 13, 2011 Moderators Share Posted April 13, 2011 cesars77, Look at the difference between what you posted a while ago and your latest algorithm: ; Original Sleep ( ($Duration * 1000 ) - TimerDiff($begin__)) Sleep( (Some number of ms) - (some other number of ms) ) ; So as long as you get a positive value of ms you get a Sleep ; Latest Sleep ($Duration * 1000 ) - TimerDiff($begin__)/1000 Sleep( some number in the thousands) - some number ; The Sleep function always returns 1 - so we get 1 - a number ; Which means nothing at all So you are nowhere near getting what you think you are. Did you try what I suggested and test to see what the values of the various variables are when you try to use them to set a duration? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
cesars77 Posted April 13, 2011 Author Share Posted April 13, 2011 ok!! Got it work properly now!! Loop looks like that now... Func WaitDelay() If ValuesScreen() = 1 Then $begin__ = TimerInit() while ScreenCheck("MainValuesScreen") = 0 Sleep(1000) wend EndIf $Loop = $Loop + $ATTEMPTS $JOINATTEMPTS = 0 If $Loop >= $BeforeSwitch AND $Count > 0 Then Sleep(1000+($Delay*1000)) Sleep ( 1000 ) If (TimerDiff($begin__) * 1000 ) < $Duration Then Sleep ( $Duration * 1000 - TimerDiff($begin__)) Endif Else Sleep(5000+($Delay*1000)) Sleep ( 1000 ) If (TimerDiff($begin__) * 1000 ) < $Duration Then Sleep ( $Duration * 1000 - TimerDiff($begin__)) Endif EndIf EndFunc But i had to add a 1 sec Sleep delay in front of the "Sleep loop", otherwise the script seems to ignore it... Thx again guys! 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