Page 1 of 1

Can't read some uservars from client

Posted: 12 Oct 2006, 10:23
by Poyz
I got this code on the server, inside the userJoin function (if (evt.name == "userJoin") {) that sets an user variable for the user that join, called "num", value 0.

So, anyone who joins the room, gets this variable num = 0.

Now on the client side, when i join a room, i get the onJoinRoom event
Let's say there are 2 users in this room, John and Mark, and me (Poyz) join the room.

Here's my code and what happens:

smartfox.onJoinRoom = function(roomObj:Room) {
var users = roomObj.getUserList();
var usersArray:Array = [];
for (var usr in users) {
var uObj = {};
uObj.uName = users[usr].getName();
var userVars = users[usr].getVariables();
uObj.num = userVars["num"];
trace ("Name = " + uObj.uName)
trace ("Number = " + uObj.num)
usersArray.push(uObj);
}
}

This should trace the names of the 3 users and theis "num" value
but this is what i get:
Output:

Name = John
Number = 0
Name = Mark
Number = 0
Name = Poyz
Number = undefined

I tryed to see if the uservars were there joining with the admin tool, and they are all set to 0.

Why can't i read my own uservar?
TIA

Posted: 12 Oct 2006, 10:52
by Poyz
It's like when i login, the server sends me an roomListUpdate without my userVars, and doesn't send me an onUserVariablesUpdate either.

Posted: 12 Oct 2006, 11:13
by Poyz
I'm trying everything i can, the server just doesnt want to send me a right roomList or a variable update.
I even put the set variable command both after the _joinRoom command and in the onJoinRoom internal event.. doesn't work

Posted: 12 Oct 2006, 12:49
by Poyz
Ok this is the problem (bug?):
the onUserVariablesUpdate is sent to every user except the one who has the var...
If i change an uservar for user X, every user receive it except him... why?

Posted: 12 Oct 2006, 14:08
by Virusescu
Why should you be notified about a thing that you did it yourself?

Posted: 12 Oct 2006, 14:12
by Virusescu
And here's what the docs say about the setUserVariables method
Stores data on the server side. When you set/update/delete one or more User Variables all the other users in the room will be notified. User variables are usefull to store user profile data that can be shared across other users.
I pasted this here to make clear that this is not a bug and this is how it was intended to work. Same as sendObject :).

Posted: 12 Oct 2006, 14:37
by Poyz
Virusescu wrote:Why should you be notified about a thing that you did it yourself?
because you didn't do it, that variable is created by the server and the server itself sets it for you. and everyone that joins that room must know that value.
I guess there is no way to make this with user vars, too bad they were perfect... tell me if i'm wrong

Posted: 12 Oct 2006, 15:29
by Lapo
can you show the code that you use on the server side to create the variable(s)?

Posted: 13 Oct 2006, 08:30
by Poyz
there is a part where the server calculates the value of xp, then:
var u = evt.user
var uVars = {}
uVars.xp = xp
_server.setUserVariables(u, uVars)

i tryed to put this also in different events and in a simple request but it never sends info to the involved client

Posted: 15 Oct 2006, 08:20
by Poyz
should i go for another way or there will be a fix or... any other solutions?

Posted: 20 Oct 2006, 14:08
by Poyz
:?:

Posted: 25 Oct 2006, 09:23
by Poyz
anyone help please? :(

Posted: 25 Oct 2006, 09:51
by Lapo
I see various problems here but I don't think it is a bug.
If you set the variable on the server side when the user joins a room the update message has already been sent to the other clients in the room but the user object did not contain any variable at that time: you are modifying them AFTER the notification is gone.

So the users should receive a onUserVariables message that tells them that a certain user update his variables.

If you want the user vars to arrive in the onJoinRoom/onUserEnterRoom you will have to add those variables BEFORE, for example at login time.

hope it's clear :)

Posted: 27 Oct 2006, 11:27
by Poyz
Hum it's not really clear why my code didnt work, because setting a variable anytime should send the info and update the user object.
Anyways i tryed setting the variable before even sending the room list update in the login function and it works, so thanks ^^
i didnt try it before because i tought setting an uvar had to be done only after joining a room (like for xt commands).
TY lapo