Harrie38 Posted October 4, 2006 Share Posted October 4, 2006 What am I doing wrong? I wrote a script to do a countdown (actually I'm using it to slowly get the "progress window" to zero). Here's the script: Global $Progr $Progr = 10 Msgbox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $Progr = $Progr to 0 Step -1 Sleep(500) Next Msgbox(160, "Timer", "5 Seconds passed!") Countdown() Func Countdown() Msgbox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $Progr = $Progr to 0 Step -1 Sleep(500) Next Msgbox(160, "Timer", "5 Seconds passed!") EndFunc I want to do a 5 seconds countdown twice, one from the basic program and one from a function. The 5 seconds countdown from the basic program is working correctly, but the one in the function is taking less then a second to finish (It's exactly the same code!) Am I doing something wrong here or is it an AutoIT bug? (hopefully the first item ;-)) Link to comment Share on other sites More sharing options...
Xenobiologist Posted October 4, 2006 Share Posted October 4, 2006 (edited) HI, $Progr = 10 Msgbox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $i = 0 to $Progr Sleep(500) Next Msgbox(160, "Timer", "5 Seconds passed!") Countdown() Func Countdown() Msgbox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $i = 0 to $Progr Sleep(500) Next Msgbox(160, "Timer", "5 Seconds passed!") EndFunc Edit: Have a look at TimerDiff() So long, Mega Edited October 4, 2006 by th.meger Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 4, 2006 Share Posted October 4, 2006 What am I doing wrong? I wrote a script to do a countdown (actually I'm using it to slowly get the "progress window" to zero). Here's the script: Global $Progr $Progr = 10 Msgbox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $Progr = $Progr to 0 Step -1 Sleep(500) Next Msgbox(160, "Timer", "5 Seconds passed!") Countdown() Func Countdown() Msgbox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $Progr = $Progr to 0 Step -1 Sleep(500) Next Msgbox(160, "Timer", "5 Seconds passed!") EndFunc I want to do a 5 seconds countdown twice, one from the basic program and one from a function. The 5 seconds countdown from the basic program is working correctly, but the one in the function is taking less then a second to finish (It's exactly the same code!) Am I doing something wrong here or is it an AutoIT bug? (hopefully the first item ;-)) You didn't reset the time variable. Put $Progr = 10 in your Countdown() function before the For line. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Harrie38 Posted October 4, 2006 Author Share Posted October 4, 2006 You didn't reset the time variable. Put $Progr = 10 in your Countdown() function before the For line. That's right, but it doesn't solve the problem. The next program is as you stated it: Global $Progr $Progr = 10 Msgbox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $Progr = $Progr to 0 Step -1 Sleep(500) Next Msgbox(160, "Timer", "5 Seconds passed!") Countdown() Func Countdown() $Progr = 10 Msgbox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $Progr = $Progr to 0 Step -1 Sleep(500) Next Msgbox(160, "Timer", "5 Seconds passed!") EndFunc This gives the same result! Link to comment Share on other sites More sharing options...
Xenobiologist Posted October 4, 2006 Share Posted October 4, 2006 Hi, did you try my script? So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
/dev/null Posted October 4, 2006 Share Posted October 4, 2006 This gives the same result!bad style will give bad results ;-))Replace:$Progr = 10 with $Start = 10and For $Progr = $Progr to 0 Step -1 with For $Progr = $Start to 0 Step -1 and it will work.Now for the problem. I don't know what's causing the error. Your code should work andif I print the value of $Progr before the For loop it shows 10. However Within the For loopit shows 0, which immediately ends the For loop. Could be a bug....CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Xenobiologist Posted October 4, 2006 Share Posted October 4, 2006 Hi, the problem is that it should be Global $Progr = 10 MsgBox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $Progr = $Progr To 0 Step - 1 Sleep(500) Next MsgBox(160, "Timer", "5 Seconds passed!") Countdown() Func Countdown() Local $Progr = 10 MsgBox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $Progr = $Progr To 0 Step - 1 ConsoleWrite($Progr) Sleep(500) Next MsgBox(160, "Timer", "5 Seconds passed!") EndFunc ;==>Countdown otherwise $Progr is 0 in the func. The $var isn't set to 10. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
/dev/null Posted October 4, 2006 Share Posted October 4, 2006 (edited) otherwise $Progr is 0 in the func. The $var isn't set to 10.it is set, but it's changed to 0 in the for loop. See my bug report.CheersKurt Edited October 4, 2006 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 4, 2006 Share Posted October 4, 2006 That's right, but it doesn't solve the problem. The next program is as you stated it: Global $Progr $Progr = 10 Msgbox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $Progr = $Progr to 0 Step -1 Sleep(500) Next Msgbox(160, "Timer", "5 Seconds passed!") Countdown() Func Countdown() $Progr = 10 Msgbox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $Progr = $Progr to 0 Step -1 Sleep(500) Next Msgbox(160, "Timer", "5 Seconds passed!") EndFunc This gives the same result! By golly... it does! I have no idea why that is. If all you need is a working timer, th.meger did post a better technique, but this is an interesting bug (as far as I can tell). It has to do with using a Global variable in a function, because it works fine if you make it "Local $Progr = 10" inside the function. Interesting... Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Harrie38 Posted October 4, 2006 Author Share Posted October 4, 2006 By golly... it does! I have no idea why that is. If all you need is a working timer, th.meger did post a better technique, but this is an interesting bug (as far as I can tell). It has to do with using a Global variable in a function, because it works fine if you make it "Local $Progr = 10" inside the function.Interesting... I don't need a timer, I'm using the script to slowly show a progressbar that's come from a value from 0 to 100 and must go to zero when the script is cancelled.There are probably more ways to do it, but I used this one (and it didn't work )Thanks for all you're help guys! Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 4, 2006 Share Posted October 4, 2006 I don't need a timer, I'm using the script to slowly show a progressbar that's come from a value from 0 to 100 and must go to zero when the script is cancelled. There are probably more ways to do it, but I used this one (and it didn't work ) Thanks for all you're help guys! Well, you've got two good tweaks to make what you had work, and I tested both: 1. Make the variable in the function local: Func Countdown() Local $Progr = 10 Msgbox(160, "Timer", "After pressing OK, the timer is set to 5 seconds and counting down") For $Progr = $Progr to 0 Step -1 Sleep(500) Next Msgbox(160, "Timer", "5 Seconds passed!") EndFunc I think it should have worked with the Global, and that might be a bug, but you have workarounds. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Harrie38 Posted October 4, 2006 Author Share Posted October 4, 2006 Well, you've got two good tweaks to make what you had work, and I tested both: Thanks for the good thinking, but I really need the variable $progr. I don't yet know from which point my script will be cancelled, so the value can be anything from 0 to 100. Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 4, 2006 Share Posted October 4, 2006 (edited) Thanks for the good thinking, but I really need the variable $progr. I don't yet know from which point my script will be cancelled, so the value can be anything from 0 to 100. Easy tweak, pass it as a parameter to your function: $Progr = 10 Countdown($Progr) Func Countdown($Delay) Local $t MsgBox(160, "Timer", "After pressing OK, the timer is set to " & $Delay & " seconds and counting down") For $t = $Delay To 0 Step - 1 Sleep(1000) Next MsgBox(160, "Timer", $Delay & " Seconds passed!") EndFunc ;==>Countdown Now you can call it with any number of seconds you like. This is also a style improvement as usage of Global variables inside functions should be minimalized (in my opinion). Edited October 4, 2006 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
/dev/null Posted October 4, 2006 Share Posted October 4, 2006 Thanks for the good thinking, but I really need the variable $progr. I don't yet know from which point my script will be cancelled, so the value can be anything from 0 to 100.O.K. but WHY does the counter and the start value have to be the SAME variable???Kurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 4, 2006 Share Posted October 4, 2006 (edited) O.K. but WHY does the counter and the start value have to be the SAME variable???KurtYou lost me... can you use the variable names in our examples to tell me which you are refering to?Nevermind, I missed that post was from /dev/null instead of Harie38. :"> Edited October 4, 2006 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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