SilverFox1405241541 0 Report post Posted May 7, 2007 I'm not sure this is the right place to post this.But I'm working on a project and I need to know how to implement a timer.Like how would I make a delay between what the user says to do and the execution?Sorry if I'm not making sense.But what i was thinking is like.User Tells system to do something => System delays it using some formula for let's say like 512 Seconds => System Finishes what user said to do.Any tips on how to implement this? Share this post Link to post Share on other sites
WeaponX 0 Report post Posted May 7, 2007 I think the PHP Sleep function will do the trick for you:http://php.net/manual/en/function.sleep.phpYou can put this in between the code that asks the user for input until it finishes... Share this post Link to post Share on other sites
Quatrux 4 Report post Posted May 8, 2007 In my opinion, the sleep function isn't good for such things, due to when sleep is being used, the server doesn't do anything, if I understand what he wants, I would say to him to rather use AJAX technology for this kind of things and 512 seconds is really a lot, it is over 8 minutes, so having ajax do it is also not the best idea.. In fact, having such a delay, I think it isn't needed, you can store the timestamp in a database and check it.. Share this post Link to post Share on other sites
SilverFox1405241541 0 Report post Posted May 8, 2007 512 seconds is really a lot, it is over 8 minutes, so having ajax do it is also not the best idea.. In fact, having such a delay, I think it isn't needed, you can store the timestamp in a database and check it.. Here are some questions: What is AJAX?What do you mean store a timestamp?How would I make the php script check the timestamp?I'm asking b/c my project is a online virtual hacking game and I"ll need to implement timers for downloads and such. I know its possible as another game, Slavehack* has such a system. *Slavehack, the slavehack name and game code is the property of its respective owner. Share this post Link to post Share on other sites
miCRoSCoPiC^eaRthLinG 0 Report post Posted May 8, 2007 I played a hell lot of SlaveHack when it had just started... As far as I remember, SlaveHack utilised JavaScript based timers along with a timestamp stored in MySQL DB.  The JS timer was displayed as a progress bar to the end-user. Right before the progress bar started animating, the current time would be written to the MySQL DB along with (I guess) the time taken to complete the ongoing operation. If the user interrupted it in between, all SH had to do was add the required time to the last registered timestamp and compare it with the current time. The difference would tell whether the user successfully completed the operation or aborted it.  To store a timestamp in the DB, you can use the in-built MySQL function called NOW(). The field where you store the timestamp has to be declared as of type TIME or DATETIME.  A typical timestamp will look like, 2007-05-08 8:30:21.  To insert the current timestamp into a MySQL field, issue the following statement: INSERT INTO table ( time_field_name ) VALUES ( NOW() );Keep in mind that this inserts a SECOND based timestamp i.e. the time lapses can be calculated from days, hours ... lowest upto the level of seconds. However, if your game requires calculations at microsecond levels (or some other fraction of a second) - you'd prolly get down on your knees and mess around with the microtime() function of PHP.  Cheers, m^e Share this post Link to post Share on other sites
SilverFox1405241541 0 Report post Posted May 8, 2007 Thanks.That'll help and I'll ask Chesso...he might know. Share this post Link to post Share on other sites
develCuy 0 Report post Posted May 8, 2007 Yes, "sleep" is not usable. And Javascript for 8 minuts???!!! Why somebody must wait 8 minuts to download a file!!!!, I think you need to add a "song choice bar" to help the victims wait. KDE have "koffee", a tool that waits n minuts and then displays: "your coffee is ready!!" or some other custom message. SilverFox, maybe your questions was made similar to the one I did when I was an student at the school. I needed an scanner for 50 photographs. Then I talked with the principal. He asked me: are you talking about 50,000 photographs??!!!, that will finish to kill our old scanner!!!. then I said: sorry, I was thinking on many photographs.... maybe 50. Hotscripts.com must have many examples for "PHP Downloader" or "PHP Download System". Â Spanish word of the day: "retorica": tenses or phrases used by lawyers, politics, etc. example: Hotscripts.com is property of its respective owners. Human law is about waste your time and get paid! Share this post Link to post Share on other sites
SilverFox1405241541 0 Report post Posted May 9, 2007 I will shorten times...I'm talking about things INGAME (ie virtual files...they are MySQL values).I think M^e gave the best advice and I'll start working on this part of my project later this week.Thanks ^^ Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted May 14, 2007 I'm not sure this is the right place to post this.But I'm working on a project and I need to know how to implement a timer.Like how would I make a delay between what the user says to do and the execution?Sorry if I'm not making sense.But what i was thinking is like.User Tells system to do something => System delays it using some formula for let's say like 512 Seconds => System Finishes what user said to do.Any tips on how to implement this?The best way to do this is with a combination of javascript and php, in your php script if you wish you can set the initial time with the php time() function and the amount of seconds of your timer, then you simply add a javascript counter function inside the body tag of your document, check out this general counter:<script type="text/javascript"> var myTime = 20; function countDown() { if (myTime == 0) { // tasks to process when the time is over } else if (myTime > 0) { myTime--; setTimeout("countDown()",1000); } } countDown();</script> Best regards, Share this post Link to post Share on other sites
SilverFox1405241541 0 Report post Posted May 14, 2007 Thanks all for the help!I haven't gotten far enough to start trying to implement but I will have more important hurdles like this to overcome so I am sure I'll ask another question sometime down the ways.Also an off topic question, how do I set a timezone? Like I want it to show my timezone not the server timezone. How do I do that? I couldn't figure it out earlier. Share this post Link to post Share on other sites
vizskywalker 0 Report post Posted May 15, 2007 Uggh, timezones are evil. In fact, trying to get the server to deal with remote timezones can be a royal pain, sometimes impossible. I guess we'd need to know what you want to do with the timezone to be able to give you the best (or a good) way of handling them. For example, if the only the needed is to display the time in the user's timezone, then using javascript is probably your best bet, as that can draw from the local computer and generate a time in the current timezone automatically.~Viz Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted May 16, 2007 Thanks all for the help! Â I haven't gotten far enough to start trying to implement but I will have more important hurdles like this to overcome so I am sure I'll ask another question sometime down the ways. Â Also an off topic question, how do I set a timezone? Like I want it to show my timezone not the server timezone. How do I do that? I couldn't figure it out earlier. I agree with vizskywalker timezones are very nasty to manipulate or configure, one way is by using javascript by using the local time used by the user, now if you would use PHP5 you can set the default timezone by using the date_default_timezone_set() php function in your scripts or by using the date.timezone ini setting in your php.ini file. Also take a look to the Appendix I, List of Supported Timezones that are referenced on the PHP manual. Â Best regards, Share this post Link to post Share on other sites
SilverFox1405241541 0 Report post Posted May 16, 2007 (edited) Thanks all I will look into these and other issues soon.I just got back from a long road trip (not really only 50 miles away but I went in loops around the city you know how San Antonio can be If you don't your not missing much) and therefore am too exhausted to code tonight and *sigh* have to go to more s##t in the city later...gosh looks like coding's slowing down Edited May 16, 2007 by SilverFox (see edit history) Share this post Link to post Share on other sites
lonelym 0 Report post Posted May 20, 2007 (edited) Ahm. Yes, I also have this question in mind. I have a beta-game (not yet finished) and I'm planning on making a mana system (simillar to Marcoland.com) wherein the mana refreshes every day. I'm not sure how to set it like that. (Am I allowed to ask questions as well?)Do I put a time stamp with the now() function that m^e has said and put an if statement when the time is equal?@Tavox Peru - That seems functional. I'll try that one out. I'm not sure how Javascript will get the time stamp from php though. I'm really confused with this subject.(LOL, I was thinking of a way to refresh the mana automatically... I said to myself, "Bah, I'll just refresh it manually. -.-;;" hehehe ") Edited May 20, 2007 by lonelym (see edit history) Share this post Link to post Share on other sites
Chesso 0 Report post Posted May 21, 2007 What I'm thinking is, that you want to create a basic timestamp in mySQL.Setup your (perhaps javascript timer) to the appropriate time, and if the page changes or refreshes (or however you handle it) compare the original beginning timestamp, with a newly fresh calculated one to re-calculate the timer display.If they stay on the page, and the timer runs out, then you'll need to still do the timestamp query and comparison (to make sure they didn't mess with the JS code), and complete it, or if they come back to the page, and it's done, show it complete and carry on.Anyway, basically something along those lines I'm thinking. Share this post Link to post Share on other sites