bug on user variable updates

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

creat326
Posts: 87
Joined: 13 Jun 2010, 09:50

bug on user variable updates

Postby creat326 » 20 Feb 2011, 18:55

Hi



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
Last edited by creat326 on 21 Feb 2011, 18:28, edited 1 time in total.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 21 Feb 2011, 13:29

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.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
creat326
Posts: 87
Joined: 13 Jun 2010, 09:50

Postby creat326 » 21 Feb 2011, 15:33

btw, what's the difference between using getApi().setUserVariable and user.setVariable ?
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 21 Feb 2011, 17:19

The 2nd performs a local change and nobody gets updated, no events fired. Not recommended.
Lapo

--

gotoAndPlay()

...addicted to flash games
creat326
Posts: 87
Joined: 13 Jun 2010, 09:50

Postby creat326 » 21 Feb 2011, 18:25

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
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 22 Feb 2011, 10:04

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.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: Thomasea and 23 guests