Can't read some uservars from client
Can't read some uservars from client
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
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
Last edited by Poyz on 12 Oct 2006, 10:53, edited 1 time in total.
And here's what the docs say about the setUserVariables method
.
I pasted this here to make clear that this is not a bug and this is how it was intended to work. Same as sendObjectStores 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.
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
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.Virusescu wrote:Why should you be notified about a thing that you did it yourself?
I guess there is no way to make this with user vars, too bad they were perfect... tell me if i'm wrong
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
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
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
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