I’m working on an online game. I’m using a MySQL database.
Players get weapons and ammo by buying them from Gun Dealers. I’m saving the ammo in the database.
My question is, will it be better to save the player’s ammo on variables and then update it into the database when he disconnects? Means everytime he shoots I will do -1 (ammo) from the variable. The other options is to directly update the database when he shoots instead.
I want to save resources. What’s the best solution & fastest solution? I want the server to be as lagless as possible.
Thank you.
Store it in memory in variable, then periodically save it to the DB. Maybe put a call in whatever object stores ammo variable to write it to the DB on object deallocation/destruction.
Whatever you do, avoid constant writes to to your db like you mention in your question. It would be a beast to try and scale.