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?
Room variables not present on client.
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:
Am I doing something wrong here?
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?
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
So it looks like its there in the array, but not accessible by name.
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.
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
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.
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.
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!
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!
Who is online
Users browsing this forum: No registered users and 137 guests