Reputation:
I have a resource table for a game I'm trying to code, and each resource has a fixed income rate over time. But I can't find any description on how to increase the stored values of the MySQL Table over time automatically.
I'm using NetBeans to connect the program with the database, but I want the values to be updated on the server without the need to run the program. Otherwise I would just have had the time recorded and just add the time difference value.
Is there a way of doing this?
Table:
Player ID: 1
Gold: 100
Wood: 100
Increase rate: 50 per hour
Upvotes: 2
Views: 454
Reputation: 505
Yes, you can by adding a scheduled event like this. However, if you update the value in the database, the value/variable stored by the program will not be updated in real-time: you have to query the database for the updated value.
Upvotes: 0
Reputation: 2388
One way of doing this is using Cron jobs and schedule some script to run. Otherwise you can simply calculate the time elapsed from the beginning and (whithout updating your DB) calculate values based on the time when your program is running.
Upvotes: 1
Reputation: 4089
You can define a cron job on the server, that runs a query to update the values.
Upvotes: 0