Serverside Room Variable updates not detected by client

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
marsoups
Posts: 167
Joined: 14 Apr 2008, 03:30

Serverside Room Variable updates not detected by client

Postby marsoups » 18 Aug 2015, 14:51

Hi,

Have a problem here where we're setting a room variable update on a room on the server end. Client (which is Unity C#) connects to this room and has a RoomVarUpdate listener attached.

However the RoomVar event is not detected on the clientside and the room var is not updated on the clientside either.

Here is the dynamic creation of the room:

Code: Select all

CreateSFSGameSettings roomSetting = new CreateSFSGameSettings();
               roomSetting.setName(gameName);
               roomSetting.setAutoRemoveMode(SFSRoomRemoveMode.WHEN_EMPTY);
               roomSetting.setDynamic(true);
               roomSetting.setGamePublic(true);
               roomSetting.setLeaveLastJoinedRoom(true);
               roomSetting.setGroupId("example");
               roomSetting.setMaxUsers(6);
               roomSetting.setHidden(false);
               roomSetting.setMaxVariablesAllowed(2);
               roomSetting.setMinPlayersToStartGame(1);
               //roomSetting.setRoomSettings(EnumSet.noneOf(SFSRoomSettings.class)); // no permissions.
               roomSetting.setRoomSettings(EnumSet.of(SFSRoomSettings.USER_ENTER_EVENT,
                     SFSRoomSettings.USER_EXIT_EVENT,
                     SFSRoomSettings.USER_VARIABLES_UPDATE_EVENT));
               List<RoomVariable> roomVarsList = new ArrayList<RoomVariable>();
               roomVarsList.add(new SFSRoomVariable("state", "INIT"));
               roomSetting.setRoomVariables(roomVarsList);
               try {
                  ISFSGameApi gameApi = SmartFoxServer.getInstance().getAPIManager().getGameApi();
                  tgtRoom = gameApi.createGame(ext.getParentZone(), roomSetting, null);
               } catch(SFSCreateRoomException err) {
               }



And then the variable is updated at a later time:

Code: Select all

ext.getParentRoom().setVariable(new SFSRoomVariable("state", "READY"));


When the players join the room, the first variable shows when that player enters the room. However, the second variable update doesn't appear to send to the clientside. I've checked all permissions and can't find anything related to this. Is there any reason for this ? If this is not possible , I'll have to send a custom event. thanks.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Serverside Room Variable updates not detected by client

Postby Lapo » 19 Aug 2015, 08:54

Hi,
the problem is with this line:
ext.getParentRoom().setVariable(new SFSRoomVariable("state", "READY"));

if you call Room.setVariable() you're updating the var on the server side only, without triggering any updates on the clients.

You need to do this instead:

getApi().setRoomVariable(room, new SFSRoomVariable("state", "READY"));


Remember: getApi() is the central place where all the major server API is exposed and it always deals with the generation of client side updates.
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 59 guests