Page 1 of 1

How to setUserVariables with false

Posted: 06 Feb 2012, 01:46
by Hatta
Hi everyone, I have some questions regarding the method setUserVariables in a server side extension.

If the method setUserVariables i set the third parameter to false, so I avoid that the event onUserVariablesUpdate is fired and that all users receive the update, I guess I have to manage it all by hand.

I had thought to read the variable, that i can set, in the moment in which the client received response from the server side extension, but does not work.
On the server side extention I have this code (I program in Java):

Code: Select all

HashMap<String, UserVariable> vars = new HashMap<String, UserVariable>();
UserVariable var = new UserVariable("ok");
vars.put("test", var);
				
helper.setUserVariables(user, vars, false);				
// ...code for send message with sendResponse

and the client

Code: Select all

sfs.addEventListener(SFSEvent.onExtensionResponse, onExtensionResponse);

// other code and function

private function onExtensionResponse(e:SFSEvent):void 
{
/* get the avatar of new joined user */
var user:User = e.params.user;
trace("test value " + user.getVariable("test"));		
}
but I get error because user variable is null. Why?
In such events e.params.user is not null?

I tried to set to true and handle the event onUserVariablesUpdate and in this case everything works.

Thank you very much

Posted: 06 Feb 2012, 22:46
by rjgtav
Hi.

If my memory isn't failing, if you specify the sendUpdate parameter to false, the server won't fire the event to any one, including the client whose variables are being set.

As the variables aren't sent to the current client, when you retrieve the variable, of course it is null, as you haven't received the response from the server. The user is not null because when you login the client already populates an User object with your information.

Posted: 07 Feb 2012, 13:11
by Hatta
Thanks for clarification.
Although, at this point, I wonder why give the possibility to set the third parameter to false. Since the event is not fired, as you may use the variables set.
Hmmmm .... think about it could be used to pass variables between server side and maybe another precisely without starting the event.

Anyway thanks again.

Re: How to setUserVariables with false

Posted: 15 Feb 2012, 18:34
by Lapo
The third parameter can be used in special cases, like for "fake" Users like NPCs etc...
Another case is when you are setting the UserVars at login time.

However there's one thing I need to point out. From your code it seems that you expect the update to come via the onExtensionResponse event, but this is not the case.
You need to listen for an onUserVariablesUpdate as you would normally do if the update was initiated from client side.

Cheers