How to setUserVariables with false

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Post Reply
Hatta
Posts: 12
Joined: 04 Dec 2011, 22:37

How to setUserVariables with false

Post 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
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post 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.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Hatta
Posts: 12
Joined: 04 Dec 2011, 22:37

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

Re: How to setUserVariables with false

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply