Page 1 of 1

bug on user variable updates

Posted: 20 Feb 2011, 18:55
by creat326

I have these lines on server side:

List<UserVariable> vars = new LinkedList<UserVariable>();
vars.add(new SFSUserVariable("posx", receivedTransform.x, true));
getApi().setUserVariables(u, vars);

In theory, since the variable is hidden (true), the client should get nothing. It's true, the client gets no variable changes but they do get a OnUserVariablesUpdate call. This is unnecesary traffic. Here it's what I have on the client:

public void OnUserVariablesUpdate(BaseEvent evt)
User user = (User)evt.Params["user"];
List<UserVariable> changedVars = (List<UserVariable>)evt.Params["variables"];
Debug.Log("User variables changed");

foreach (UserVariable v in changedVars)
Debug.Log("variable changed:" + v.Value + " to:" + user.GetVariable(v.Name).Value);

I will get tons of "User variables changed" text on the console but no one single "variable changed:" line. So no variable has changed from the client point of view, but it does get notification.

Joaquin Grech

Posted: 21 Feb 2011, 13:29
by Lapo
Yes, I can reproduce it, thanks for noticing. We'll add a fix in the next release.
You can anyways avoid the problem by using the API overloaded method:

Code: Select all

setUserVariables(User owner, List<UserVariable> variables, boolean fireClientEvent, boolean fireServerEvent)

setting the 3rd param to false.


Posted: 21 Feb 2011, 15:33
by creat326
btw, what's the difference between using getApi().setUserVariable and user.setVariable ?

Posted: 21 Feb 2011, 17:19
by Lapo
The 2nd performs a local change and nobody gets updated, no events fired. Not recommended.

Posted: 21 Feb 2011, 18:25
by creat326
place it on the docs please :)
that's a big thing.

Actually, do you want that behaviour? if the variables are set to hidden that should be enough right?

Joaquin Grech

Posted: 22 Feb 2011, 10:04
by Lapo
It is in the docs. We state all over the place that non-commented methods in the Java API mean ... do not use :)
We are sorry... but until the javadoc becomes less crappy and allows method hiding, it's a real pain in the butt to list all public methods.