Events not triggered

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

Post Reply
imteractive
Posts: 20
Joined: 06 Jan 2012, 21:09

Events not triggered

Post by imteractive »

Hi,

I have a server extension (written in Java) that is assigning some user variables on a "USER_JOIN_ZONE" event handler.

The problem is that if I use the code below, the client is notified of the variables update and everything is fine:

Code: Select all

SFSUserVariable energy = new SFSUserVariable("energy", 100);	    	
ArrayList<UserVariable> userVariables = new ArrayList<UserVariable>();
userVariables.add(energy);
this.getApi().setUserVariables(user, userVariables);
However, if I use this (which makes a lot more sense to me), the client is not notified of the changes, neither the variables are updated on the client:

Code: Select all

SFSUserVariable energy = new SFSUserVariable("energy", 100);	 
user.setVariable(energy);
Can someone tell me what's the difference here?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Events not triggered

Post by rjgtav »

Hi.
The difference is that those methods (user.setVariable(), room.setVariable(), etc) are for internal use only by the server's internal API, as they, in this case, just set the variables. When you update a variable, you have to set it in the user/room's object and then notify the necessary users about that change. The SFSApi's methods do all those internal procedures on the background automatically, so it's suggested for you to use it instead of using the direct methods.
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.
Post Reply