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.
Energy Regeneration
- a_bertrand
- Posts: 1536
- Joined: Mon Feb 25, 2013 1:46 pm
Re: Energy Regeneration
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
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
Mad programmer and annoying composer
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Energy Regeneration
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.