Forum BigDB NaNs in PlayerObjects

Discussion and help relating to the PlayerIO database solution, BigDB.

NaNs in PlayerObjects

Postby LostBytes » May 31st, 2011, 8:40 pm

Hi there, I have stats for my game for each player in player objects and some of them tend to become NaN for some reason. This happens only for some players and probably only in first write. I have no idea what might be causing it, I made sure I don't divide by zero but that didn't help. If anyone could help me I would really appreciate it :)

here some code:

I initialize stats like this
Code: Select all
if (!stats.Contains("FightWinRatio")) stats.Set("FightWinRatio", 0.0f);
if (!stats.Contains("FightCount")) stats.Set("FightCount", 0);


and I manipulate with data like this
Code: Select all
DatabaseObject stats = PlayerObject.GetObject("Stats");
int fightCount = stats.GetInt("FightCount");
int wonSum = (int)(stats.GetFloat("FightWinRatio") * fightCount);
fightCount++;
// this is here only to make sure we don't divide by zero (but it shouldn't happen it anyway)
if (fightCount < 1) fightCount = 1;
stats.Set("FightCount", fightCount);
if (won) {
   wonSum++;
}
         
stats.Set("FightWinRatio", (float)wonSum / (float)fightCount);
PlayerObject.Save();


Those are only two places I use those stats in my code.
LostBytes
Paid Member
 
Posts: 20
Joined: May 17th, 2011, 7:41 pm

Re: NaNs in PlayerObjects

Postby LostBytes » June 1st, 2011, 8:20 am

Ok, I just tried checking for NaNs before setting variable like this
Code: Select all
if (System.Single.IsNaN(result))
   result = 0.0f;
stats.Set("FightWinRatio", result);


but it still doesn't help. Is it possible that something goes wrong during saving whole PlayerObject or while reading back those data?
LostBytes
Paid Member
 
Posts: 20
Joined: May 17th, 2011, 7:41 pm

Re: NaNs in PlayerObjects

Postby Oliver » June 1st, 2011, 12:01 pm

Hm, that's awkward.

Are you sure that's all the code that's accessing those objects, and the properites are set before you load them? It sounds like one of those things where you need to add a bunch of logging to find where the problem is.

I can't rule out that it's a BigDB error, but my stomach tells me it's not.

Probably the best thing to do would be to figure out how to reliably reproduce it; then if it's in your code it should be easy to fix, and if it's in ours it will be easy to fix for us.

- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: NaNs in PlayerObjects

Postby LostBytes » June 1st, 2011, 12:42 pm

Yeah I am sure that this properties are accessed only from this code. I tried to make simple example to reproduce it but I couldn't reproduce it outside of my game. It also happens only on live server, when I tested it on dev server everything was ok.
I do not know how to use logging on live server. Is that possible?
LostBytes
Paid Member
 
Posts: 20
Joined: May 17th, 2011, 7:41 pm

Re: NaNs in PlayerObjects

Postby Oliver » June 1st, 2011, 2:29 pm

You can use the ErrorLog service to write errors to your games errorlog for debugging.
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am


Return to BigDB



cron