Page 1 of 1

SFS2X how to set Global Room Variables

Posted: 31 Aug 2011, 16:20
by krishsalt
Hi,

I am a new in Java. Please feel to read my English :)

Using Flex side I am creating a room with Extension with Room Variables like bellow

// Flex Code bellow

var settings:SFSGameSettings = new SFSGameSettings("gameRoom1");
settings.maxUsers = 2;
settings.maxSpectators = 10;
settings.isPublic = true;
settings.minPlayersToStartGame = 2;
settings.notifyGameStarted = true;
settings.leaveLastJoinedRoom = false;
settings.extension = new RoomExtension("sfsGame", "sfs2x.extensions.games.pingPong.SFSPingPong");

// Create some Room Variables
var roomVars:Array = [];
roomVars.push(new SFSRoomVariable("gameStarted", false));
roomVars.push(new SFSRoomVariable("gameType", "Ping"));
roomVars.push(new SFSRoomVariable("minRank", 10));
roomVars.push(new SFSRoomVariable("type", "fun"));
roomVars.push(new SFSRoomVariable("desc", " game, public, bestScore > 100"));

settings.variables = roomVars;

sfs.send(new CreateSFSGameRequest(settings));

Room is created but the problem is another player is entered Room variables not getting,

By using Server side Java we can set property Global so every one can get Room variables.

Can you please help to me how to write java Server side Code to set Global.


Advance Thanks
Krishsalt

Posted: 31 Aug 2011, 16:36
by rjgtav
Hi. So here's an example of a way you can do it:

ArrayList<SFSRoomVariable> roomVars = new ArrayList<SFSRoomVariable>();
//the second true you can change to false, as it sets if the variable is persistent or not:
roomVars.add(new SFSRoomVariable("myVar", myValue, false, true, true))
//sender: the user that sent the extension request. If the extension sets the variables without an user sending a request, then you can set it to null
//room: the room where the variable is being set.
//You can get the room, for example, by using:
//Room room = SmartFoxServer.getInstance().getZoneManager().getZoneByName("myZoneName").getRoomByName("myRoomName");
getApi().setRoomVariables(sender, room, roomVars);

Re: SFS2X how to set Global Room Variables

Posted: 11 Nov 2017, 11:33
by sankarganesh86
Hi,

I create a room in java server side after receive a request from client AS3, Room created successfully but at the time of room creation i set some room variables that is not received after room created in client side, Below i added my code

CreateRoomSettings settings = new CreateRoomSettings();
settings.setName(roomName);//---Used to create a room Name---
settings.setMaxUsers(5);
settings.setMaxVariablesAllowed(20);
settings.setExtension(new RoomExtensionSettings ("SkyTeenpatti_logic","vali.logic.TeenPattiLogic"));
settings.setAutoRemoveMode(SFSRoomRemoveMode.WHEN_EMPTY);
settings.setDynamic(true);

ArrayList <RoomVariable> rs = new ArrayList<RoomVariable>();
rs.add(new SFSRoomVariable("isGameRunning",false));
settings.setRoomVariables(rs);

try
{
getApi().createRoom(zone, settings, null);
}
catch (SFSCreateRoomException e)
{
trace("Room Create Exception Received");
}

Re: SFS2X how to set Global Room Variables

Posted: 13 Nov 2017, 09:41
by Lapo
Hi,
the server code is right so I don't see why you shouldn't receive the variables on client side.

Keep in mind that variables are seen only from users joined in the Room. If you want variables to be available even to users not joined you will need to set them as global.

In other words:

Code: Select all

RoomVariable myVar = new SFSRoomVariable("myVar", "myValue");
myVar.setGlobal(true);


Hope it helps