Booleans in user variables do not work correctly

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

Moderators: Lapo, Bax

Post Reply
jalava
Posts: 40
Joined: 03 Sep 2007, 12:23

Booleans in user variables do not work correctly

Post by jalava »

My server code initializes the user with following variable:

Code: Select all

			UserVariable isVIP = 
				new UserVariable(String.valueOf(playerTypes.isVip()), UserVariable.TYPE_BOOLEAN);
			variables.put("isVip", isVIP);
When other users enter same room they get the variable as:

Code: Select all

<msg t='sys'>
<body action='joinOK' r='26'>
<pid id='0'/><vars />
<uLs r='26'>
<u i='0' m='0'><n><![CDATA[statikbuzz]]></n>
<vars><var n='isVip' t='b'><![CDATA[true]]></var></vars>
</u></uLs></body></msg>
However, getVariable("isVip") returns string false, why?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

In UserVariables booleans should be passed as "0" or "1" instead of "true" or "false". This is mainly done to save bandwidth (1 character vs 4-5).

So instead of:

Code: Select all

String.valueOf(playerTypes.isVip())
use this:

Code: Select all

new UserVariable(playerTypes.isVip() ? "1" : "0", ..., UserVariable.TYPE_BOOLEAN); 
HTH
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply