As mentioned, you could use php to log the last action/logout of the user in a DB (or cookie). However, the practicalities of doing this are far more involved than they would first appear. For instance, if a player did not do anything for 3 minutes, nothing would happen to the 'points' as php is 'spent' before the browser shows the page.
Also as mentioned, you need javascript:
http://www.w3schools.com/js/js_timing.asp
That may give you an idea of how to use time functions in js.
Mixed with Ajax (usually js with php [or XML]), you can create some powerful time-dependent functions ideally suited to your type of game. But a caveat: because ajax functions make calls to the server, if you have lots of players online at the same time, your server could get bombarded with calls -> major problem.
Server calls will be unavoidable if the game is meant to be played against/with other players. You may find that other languages would be more suitable, e.g. Java (I know absolutely nothing about it though).
diafol
Keep Smiling
10,668 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
You may already be thinking of this, but one idea is to make two timers.
One is a PHP timer(as described above, using dates or timestamps).
Two, if you want to enhance the user's experience, make a JavaScript timer as well, which doesn't alter the user data in any way but provides a visualization for the user. That way you don't have to worry about clogging up your server with excessive queries.
Also, for the PHP timer, keep in mind that if you want the regen to happen every 3 minutes, what happens if the user loads the page at 4 minutes from his last action? He needs to get 1 energy point, but you can't simply the current timestamp in the database, or else he will be shorted a minute of regeneration.
Lsmjudoka
Junior Poster in Training
76 posts since Apr 2009
Reputation Points: 10
Solved Threads: 9
Skill Endorsements: 0
cereal
Veteran Poster
1,146 posts since Aug 2007
Reputation Points: 344
Solved Threads: 223
Skill Endorsements: 22
@TiberS
You think he's still searching after over 6 months?
diafol
Keep Smiling
10,668 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
Further discussion on this is not necessary.
1- OP's question was regarding something that could keep track of a game user's energy regeneration. This was answered, a timestamp comparison(to determine how much time has passed) can be used to distribute any necessary energy when the user loads the page.
2- If you use a timestamp comparison as listed above, it is not resource intensive on your server.
3- Javascript is client-side, meaning it cannot update the user's energy in the DB unless you're talking about using Ajax and increasing server stress.
4-This discussion is old. If anyone has a specific question about timers, start a new thread.
Lsmjudoka
Junior Poster in Training
76 posts since Apr 2009
Reputation Points: 10
Solved Threads: 9
Skill Endorsements: 0
Just for completeness, w3fools is a great site, but I think w3schools actually uses functions in its examples, not code. The 'javascript statement' is unfortunate. I agree you never place code in a setTimeout.
diafol
Keep Smiling
10,668 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57