isPlayer/isSpectator(), playerIndex/getPlayerIndex() in User

You think you've found a bug? Please report it here.

Moderators: Lapo, Bax

Post Reply
Sarevok
Posts: 75
Joined: 12 Apr 2011, 22:12

isPlayer/isSpectator(), playerIndex/getPlayerIndex() in User

Post by Sarevok »

Tonight I found strange behavior in User class. It seems like isPlayer field is not compatible with isSpectator() method. In my case, isPlayer field is always set to false (even when user.getPlayerIndex() > 0), while isSpectator() method returns correct result (true when user.getPlayerIndex() == -1, and false when user.getPlayerIndex() > 0).

The same thing goes on with playerIndex/getPlayerIndex() pair. playerIndex is always set to 0, while getPlayerIndex returns correct value for the user.

Ok, we shouldn't access class fields directly, but it is strange behavior nevertheless. I used isPlayer/playerIndex fields accidentally tonight, and it took me almost one hour to figure out what is going on.

If we are not supposed to use playerIndex and isPlayer fields, then you should make them private (to prevent use by accident), or at least mark them in documentation as fields for internal use, to warn people about possible problems.
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

Thanks for reporting this. I have moved the thread to an more appropriate place.
Smartfox's forum is my daily newspaper.
Post Reply