Page 1 of 1

userVariables not works for AS 3.0

Posted: 03 Feb 2007, 09:41
by vylcho
Try to set userVariables with:

var obj:Object = new Object();
obj.score = 123;
smartFox.setUserVariables(obj);

Also in code have:

smartFox.addEventListener(SFSEvent.onUserVariablesUpdate, onUserVarUpdate);

function onUserVarUpdate(evt:SFSEvent) {
var u:User = evt.params.user as User;
var userVars:Array = evt.params.changedVars;
}

After debug have in array userVars:
[0] = "score" /here need to be 123 ???? /
length = 1
score = true

Also:
u.getVariable("Score") not works. The only way to get use variables is with:
u.getVariables()[0]

Posted: 04 Feb 2007, 15:24
by Lapo
Premise:
if you set your User variables all the other clients in the room will receive a notification except you.

Are you testing with at least two clients? One that sets variables and the other one that receives them?

thanks

Posted: 04 Feb 2007, 18:54
by vylcho
Hi Lapo,
Of course I test with more that one client. In fact with 3-4 clients and I receive event onUserVariablesUpdate only in other clients . User wich set varialbe not receive this event and I make debug for other client . In fact first log in one user, after that user in debug mode, and then third user which set user variable 'score' . I'm read all documentation (for uservariables ) and also avatar chat and think make all correctly.

Posted: 04 Feb 2007, 19:02
by Lapo
I see a problem here:

Code: Select all

 obj.score = 123; 
but you then try to retrieve the variable like this:

Code: Select all

 u.getVariable("Score")
"score" != "Score"

Posted: 05 Feb 2007, 08:28
by vylcho
I try with u.getVariable("Score") and with u.getVariable("score") and problem it's not in upper case because I debug what have in array userVars .
From debug mode:
--> [0] = "score"
--> length = 1
--> score = true
So array have only one element with value 'score' and not with value 123 which is correct. I think the problem is in the way that AS 3.0 present Array. In AS 3.0 not have named Array example
var u:Array = new Array();
u['score'] = 123; -- > It's not correct !!!
and is used Object instead of that.
var u:Object = new Object();
u['score'] = 123;

Posted: 05 Feb 2007, 08:58
by Lapo

Code: Select all

 var u:Array = new Array();
u['score'] = 123; -- > It's not correct !!! 
Of course it is. Actionscript arrays can be both indexed or associative.
The compiler does not complain about that.
There's of course an ambiguity between associative arrays and "maps" or "dictionaries" created with plain Objects, but it's perfectly legal.

Back to the topic: we don't seem to be able to reproduce the problem.
We can send user variables from one client and receive them without problems.

A couple of suggestions:
1. we're using the latest API. Version 1.3.5
Are you using this version? Just use the getVersion() method to check

2. dump all the variables
This is the code we use to check the variables that are received by the other clients:

Code: Select all

function onUserVariablesUpdate(evt:SFSEvent):void
{
	var user:User = evt.params.user
	
	debug("user var update: " + user.getName())
	var vars:Array = user.getVariables()

	for (var key:String in vars)
	{
		var v:Object = vars[key]
		debug("\t" + key + " --> " + v)
	}
}
It shows all they keys and values.
Can you try it and see if it shows the correct values?

Posted: 05 Feb 2007, 09:21
by vylcho
I found main mistake which I make. I used to get uservariables from event:
evt.params.changedVars
and you get variables via user (u.getVariables()).
Now it's work.
Tnak's for the help.

Posted: 05 Feb 2007, 09:50
by Lapo
ah ok, great.
The changedVars array is a list of the names of the variables that changed. It can be helpful when working with many variables.