Room variables not present on 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

mr_malee
Posts: 29
Joined: 08 Jun 2007, 03:21

Room variables not present on client.

Postby mr_malee » 16 Nov 2010, 00:38

creating a room from a client with some variables are not being set on that client.

I want to create a variable on the room, not owned by any client, which is available to all clients and can be changed by all clients.

How do I do this client side?
mr_malee
Posts: 29
Joined: 08 Jun 2007, 03:21

Postby mr_malee » 16 Nov 2010, 05:36

so I've tried creating a room server side with some variables, the room gets created no problem. But the client still is not receiving these variables!

Here's my room create code:

Code: Select all

//zone
      
      Zone zone = getParentExtension().getParentZone();
      Room room = user.getLastJoinedRoom();
      
      //variables
      
      RoomVariable host = new SFSRoomVariable("host", params.getInt("host"));
      host.setPrivate(false);
      host.setHidden(false);
      host.setPersistent(true);
      
      List<RoomVariable> roomVariables = new ArrayList<RoomVariable>();      
      roomVariables.add(host);
      
      //settings
      
      CreateRoomSettings settings = new CreateRoomSettings();
      
      settings.setName(params.getUtfString("name"));
      settings.setGame(true);
      settings.setDynamic(true);
      settings.setMaxUsers(3);
      settings.setMaxVariablesAllowed(1);
      settings.setMaxSpectators(0);
      settings.setAutoRemoveMode(SFSRoomRemoveMode.WHEN_EMPTY);
      settings.setRoomVariables(roomVariables);
      
      //create the room
      
      try {
         
         getApi().createRoom(zone, settings, user, true, room, true, true);
      }
      catch (SFSCreateRoomException error) {
         
         //Do nothing
      }


Am I doing something wrong here?
mr_malee
Posts: 29
Joined: 08 Jun 2007, 03:21

Postby mr_malee » 16 Nov 2010, 05:58

I think the client API might be broken a little when accessing roomVariables by name. Here when I receive the onRoomJoined event I trace out thse values

Code: Select all

private function onRoomJoin(event:SFSEvent):void {
         
         var room:Room = event.params.room;
         
         trace(room.getVariables()); //[RVar: host, type: Int, value: 5, isPriv: false]
         trace(room.getVariable("host")); //traces nothing
         trace(room.containsVariable("host")); //false
      }


So it looks like its there in the array, but not accessible by name.
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 16 Nov 2010, 08:16

I want to create a variable on the room, not owned by any client, which is available to all clients and can be changed by all clients.

How do I do this client side?

This can't be done from client side. From client all variables created are assigned to that client.

In order to create Server-owned variables you need to either create the Room and variables statically from the Configuration (AdminTool) or dynamically via Extension code.
From the server side you just need to pass a null as the owner of the variables to assign them to the Server
Lapo
--
gotoAndPlay()
...addicted to flash games
mr_malee
Posts: 29
Joined: 08 Jun 2007, 03:21

Postby mr_malee » 16 Nov 2010, 21:23

ok. But how come the variable can't be accessed using room.getVariable(name) on the client side, but exists in the getVariables() array?
mr_malee
Posts: 29
Joined: 08 Jun 2007, 03:21

Postby mr_malee » 17 Nov 2010, 04:11

Getting some more RoomVariable weirdness on the client side.

when I create a room through an extension which makes a room variable, that variable can only be accessed by the client through the room.getVariables() method. However, after a room is made and at some point the room variable is changed the updated room variable can only be accessed using room.getRoomVariable(name), at this point the array of room variables is not up-to-date.

Can someone please explain this logic to me? Shouldn't the list of roomVariables contain the same data as a call to getRoomVariable(name)?

This is really confusing if its not the case.

*As a workaround I've created a RoomUtil class for getting room variables, if the variable exists using "getRoomVariable(name)" then return that variable, otherwise look through the list of variables. It works, but I wish I didn't have to do this.
mr_malee
Posts: 29
Joined: 08 Jun 2007, 03:21

Postby mr_malee » 17 Nov 2010, 06:30

even more weirdness. I think whats happening is variables are being duplicated on the client side, here's whats happening:

1. Client sends extension request "createGame"
2. Server makes room with 4 initial variables
3. Client receives events, roomVariables only accessible through room.getVariables()
4. Client sends extension request to change 3 variables.
5. Server changes variables, broadcasts response
6. Client receives updated variables. Both getVariables() and room.getVariable() have these values now, except the total number of variables in the array is now 7 instead of 4!
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 17 Nov 2010, 08:03

This is going to be addressed in the RC1a update, out this week.
Thanks for posting.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 137 guests