- Home /
Unity - MySQL data loss
Hello!
I made a simple game with a leaderboard and achievements system. I am using php and MySQL for storing the data. The score saving works flawlessly, but the achievement system is glitchy. In my MySQL database, I have only one int type field for all the achievements. The concept is simple, I convert the array of achievements to a decimal number from the boolean values. When it works, it works perfectly, I don't think, the problem is with this. When it reads out from the database (using simple WWW forms), a static variable gets the data.
Old achievements can't be get again. However, sometimes in the middle of the game, it forgets I already have one. Last time I tested I got an achievement that I already had, I knew, something will be wrong, I looked at the database, and there was a 0 at my name in the achievements field. I was playing it in webplayer and I searched for the log file. I saw, that when I got the achievement again, it sent the right value toward the php (the game saves the achievement data when you get one, not at the end of the game). So it wasn't 0 but 191 (10111111) which means first 6 and 8th achievemnt was completed. It's perfectly all right, but it sent a 0 into my database (or cleared the data, the field's default value is 0).
Anyway, I restart the game by reloading scene, but it seems like, the problem comes from somewhere else.
I don't expect an exact answer based on what I wrote above as I didn't provide source code (there are multiple scripts that do the job the), but what do you think, where should I search for the problem? I am totally confused right now.
Still didn't find the problem. I constantly log and look at the variables when it saves and do other things. Everything looks all right! WWW.error doesn't give an error, I log the full URL with the parameters. It looks flawless.
*http://mydomain/supermax_db/ach_save.php?name=TestUser∾h=19&hash=a6625be8c53d8a79410d955c3db72ce8*
There it is, ach=19 which means it should write 19 into the database which mean, 1st, 2nd and 5th achievements are done. Sometimes it works, sometimes I get a 0 in my database.
I am at 000webhost, but I don't think it is the host's problem as from more than 400 score submission 400 worked well. It's flawless.
I also tried to do it at the end of the game, not at when a player unlocks an achievement. Same bad result (sometimes).
Now I guess it is related it is related to the game restarting. I was checking my database in php$$anonymous$$ySQL everytime I unlocked an achievement, the new data was always there. However, sometimes, when I restarted the game after a "Game Over", I lost it (it reloads the current level anyway). The PostAchievements coroutine runs only when a player get a new achievement, so I am still confused, it's like it runs when I restart it and send a 0 to the database... sometimes.
I am less confused now, but still. I don't know, what to do.