- Home /
How often to write in database
Hi, I am working on a project where the player collects coins (mario style). I would like to write how many coins the player has earned in a database. Do i do that every time i collect a coin (which is pretty often, like every second) or? Is this a slow process? Is it a mistake/bad style of programming? Whats the solution for that? Hilfe <3
You don't have to worry that much if the process will end in a second on player devices. But I would go with global static variable to store currently collected coins and store/write that coin count to database after level end/fail sequence.
Answer by bramieboy100 · Jul 29, 2017 at 05:51 PM
Is it an online database? If not it wouldn't be that hurtful to update the database every second because the only update that database gets is from you and not other players.
Answer by CarllosMiranda · Jul 29, 2017 at 11:49 PM
Store the score on a variable, then pass this to the databse. Almost all the games are like this, if ur computer shuts down on the half of the way, you'll lose all your achievements.
Answer by TheSOULDev · Jul 29, 2017 at 11:56 PM
Depends on how often you need it to be updated. If it's a real time multiplayer game, and you need everyone to see what the player has collected, then yes, you will need to write every coin collection. However, if you need to complete a level, then it's best you write the score to a variable you will send to your database once the level is complete.
At this point, however, I don't think you have to worry about such microoptimization - usually it's only important on big scales and on SSDs on servers, which you don't seem to be using yet. Writing is not a very complex operation, anyways.
Your answer
![](https://koobas.hobune.stream/wayback/20220612131456im_/https://answers.unity.com/themes/thub/images/avi.jpg)