View Full Version : Looking for a timer solution
What I have is a function containing a series of functions (10). What I want, and almost need to do is add 1-3 seconds before each one.
Application.sleep does not work in this case because it locks the app and there's no way to use a cancel button.
I tried a empty While loop which waits for the time to enter 3 seconds from the OnTimer page, but it doesn't work, at all, not in this situation.
Anyone have any ideas I can work off of? I'm just not coming up with anything.
function blahblah()
if blahblah1 then
function blahblah1()
end
some kind of timer
if blahblah2 then
function blahblah2()
end
some kind of timer
if blahblah3 then
function blahblah3()
end
end
etc...
thanks in advance for any help
Jon
yosik
07-05-2006, 11:02 PM
You can use the System.GetTime action (which gives you the curent time) combine with the StringToNumber action to change the above from a string to a number. Then you would substract two values of time from each other to get the difference/time passed. You can use the "delta" argument (a value in seconds) when you call the function to set your waiting value.
Something like this:
function myTimer(delta)
--Set starting time based on minutes and second values. Returns a number
starttime = String.ToNumber(System.GetTime(3))*60 +String.ToNumber(System.GetTime(2));
--Set initial value for currentime
currenttime =String.ToNumber(System.GetTime(3))*60 +String.ToNumber(System.GetTime(2));
--Check how much time has elapsed
while ((currenttime - starttime) < delta) do
currenttime =String.ToNumber(System.GetTime(3))*60 +String.ToNumber(System.GetTime(2));
end
end
Then you can call this function whenever you want:
-- Wait for 3 seconds
myTimer(3)
Hope that helps
Yossi
You can use the System.GetTime action (which gives you the curent time) combine with the StringToNumber action to change the above from a string to a number. Then you would substract two values of time from each other to get the difference/time passed. You can use the "delta" argument (a value in seconds) when you call the function to set your waiting value.
Something like this:
function myTimer(delta)
--Set starting time based on minutes and second values. Returns a number
starttime = String.ToNumber(System.GetTime(3))*60 +String.ToNumber(System.GetTime(2));
--Set initial value for currentime
currenttime =String.ToNumber(System.GetTime(3))*60 +String.ToNumber(System.GetTime(2));
--Check how much time has elapsed
while ((currenttime - starttime) < delta) do
currenttime =String.ToNumber(System.GetTime(3))*60 +String.ToNumber(System.GetTime(2));
end
end
Then you can call this function whenever you want:
-- Wait for 3 seconds
myTimer(3)
Hope that helps
Yossi
Sure does. TY sir. ;-)
Jon
DUDE! that's perfect. I wish I knew as much as you guys about this script engine. Some of yas are so good it scares me.
Jon / Animal
Beware that this kind of a approach utilizes CPU with a 100% load while the myTimer is running.
Intrigued
07-06-2006, 08:51 AM
Beware that this kind of a approach utilizes CPU with a 100% load while the myTimer is running.
Confirmed here. The CPU needs to have just 1ms for each of those loops and all would be good.
I'd say give us a little more detail of your project and we may find an alternative way that may even be better suited for you project's needs.
yosik
07-06-2006, 03:33 PM
I checked the CPU usage while running the myTimer function and didn't go over 60%.
True, I have a dual core machine, so maybe that's the reason.
Yossi
Ok, I read the thread and sure enough it sorta clamps down on the CPU a bit. I had a While loop also and had the same thought about redundant cycling for 3 seconds. And though this works and frees the app for Cancel option to even be used, it does have a draw back.
So, let me TRY to not get long winded here. <Bahahaha>
The project is a bit hard to explain, but this section is extensive, alot of things are going on at this point of the process. There are 304 lnes of code (uncleaned) Your PC is going on a little (safe) roller coaster ride.
The app is a game launching utility. The whole idea of the timer is two-fold.
1) The user needs to be able to have enough time to read what step the process is in (4 words ea).
2) The user must be given enough chance/time to cancel the process at any time.
The main function w/10 sub functions are setup just as in my first post. For each function it checks the registry to see if that option has been selected.
I'll post a small piece of it. it is kinda redundant and raw <shrug>
I don't know if I posted it right but here goes,......I did remove the reg addresses first... sorry
-- START -> CLOSE ALL OPEN WINDOWS
sLP_CloseAllWindows = Registry.GetValue(HKEY_CURRENT_USER, "REMOVED ADDRESS", "LP_CloseAllOpnWindows", false);
if (sLP_CloseAllWindows == "1") then
sProcTitle = "Close Open Windows";
Paragraph.SetText("Process2_Para", "\r\n\r\n"..sProcTitle..":\r\n\r\n Working...");
Paragraph.SetVisible("Process2_Para", true);
Timer_Sec(1);
-- Run process global function
CloseOpnWindows();
ProcErrorNamInsert()
Timer_Sec(1);
Paragraph.SetVisible("Process2_Para", false);
end
-- END -> CLOSE ALL OPEN WINDOWS
Progress.SetCurrentPos("Launch_ProgBar", 10);
CancelProcess();
-- START -> CLOSE ALL RUNNING PROCESSES
sLP_KillProcesses = Registry.GetValue(HKEY_CURRENT_USER, "REMOVED ADDRESS", "LP_KillProcesses", false);
if (sLP_KillProcesses == "1") then
sProcTitle = "Stop Running Processes";
Paragraph.SetText("Process2_Para", "\r\n\r\n"..sProcTitle..":\r\n\r\nWorking...");
Paragraph.SetVisible("Process2_Para", true);
Timer_Sec(1);
-- Run process global function
KillAllProcesses();
ProcErrorNamInsert();
Paragraph.SetVisible("Process2_Para", false);
Timer_Sec(1);
end
-- END -> CLOSE ALL RUNNING PROCESSES
Oops!
Keep in mind, the last functions/options are, clear memory, "run" list, launch game.
OK figured it out. pretty simple as usual.
All you have to do is add the functions to a numeric table and call the fucntion/table number on the OnTimer page. No spinning loops.
It really doesn't matter that I post my project idea and some code here, the project will be free anyway. ;-)
Powered by vBulletin™ Version 4.0.6 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.