Energy Regeneration

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
Fireal
Posts: 11
Joined: Sun May 21, 2017 5:51 pm

Energy Regeneration

Post by Fireal »

Hey guys, I'm trying to figure out the best way to handle how energy restores for my game. At first I was just going to run a cron every 10 minutes adding 10 energy points to all users. However, that didn't seem right because certain users perform energy depleting actions at different times, and I would want the regeneration to be 10 minutes from their last action. With that said, how would you handle this?

Add 10 to a user's energy 10 minutes after they performed their last action.

Only thing I can think of is starting to use timestamps in the user tables. By the way I am using PHP/MySQL. :mrgreen:
User avatar
a_bertrand
Posts: 1537
Joined: Mon Feb 25, 2013 1:46 pm

Re: Energy Regeneration

Post by a_bertrand »

You could have different ways to do it:
1) Have a cron every min which queries who did an action before 10 min ago => restore energy
2) When a page load you run basically the same as in point 1 (but doesn't require a cron, yet it may be run a lot more often, so you may need to have some way to make it less frequent or extremely quick)
3) When a page load for a given user, the check (of point 1) is done on his/her player only
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Energy Regeneration

Post by hallsofvallhalla »

yeah a timestamp in the table then every reload checks the timestamp but you could also not make it a static minute or amount, you could make each action affect the time and amount based on the action.
Post Reply

Return to “Advanced Help and Support”