database - Calculate resources in a webbrowser game in real time -


i decided write web browser game. mind comes sick when try think how code resources shown of each player when display website.

for example:

user 1 have 500 gold now, , produces +100 gold each hour, how can show real resources when user open website?

what best way?

i think update database of each user adding resources every second suicidal.

the think have no idea how code.

any ideas?

thanks

when user interacts website, @ date of last time updated gold amount. if it's more 1 hour, increment amount of gold of number of hours passed since it's last interaction, , update stored date.

you may optimisation on principle avoid testing @ each user request during session (use cache, of store date in session).

update: store next update time instead of last, avoid multiple calculations (that store timestamp of current update + 1 hour). , compare current time stored time.


Comments

Popular posts from this blog

javascript - Unusual behaviour when drawing lots of images onto a large canvas -

how can i manage url using .htaccess in php? -

javascript - Chart.js - setting tooltip z-index -