SFS2X how to set Global Room Variables

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

krishsalt
Posts: 9
Joined: 31 Aug 2011, 16:05
Location: India
Contact:

SFS2X how to set Global Room Variables

Postby krishsalt » 31 Aug 2011, 16:20

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
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 31 Aug 2011, 16:36

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);
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.
sankarganesh86
Posts: 108
Joined: 06 Jan 2010, 09:50
Location: chennai
Contact:

Re: SFS2X how to set Global Room Variables

Postby sankarganesh86 » 11 Nov 2017, 11:33

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");
}
Sankar.G
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFS2X how to set Global Room Variables

Postby Lapo » 13 Nov 2017, 09:41

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
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X ActionScript 3 API”

Who is online

Users browsing this forum: No registered users and 15 guests