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

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

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

ios - I get the error Property '...' not found on object of type '...' -