Global Room variable

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

near
Posts: 6
Joined: 05 May 2016, 15:56

Global Room variable

Postby near » 09 May 2016, 15:25

Hi.
I have some problem with room variable.
I want set a room variable true when the room, created by some user is full.
I want that this value will be fire to all user insiede room and inside the lobby, so the button of the game is destroy if the game is started and if some user exit from the room i don't want show the button again.
When some user want create a game this is the code (client side)that i use to create room:

Code: Select all

  RoomSettings settings = new RoomSettings(inputNomePartita.text.Replace(" ", "").Trim());
                settings.GroupId = "games";
                settings.IsGame = true;
                settings.MaxUsers = numeroMaxDecisoDaOwner;
                settings.MaxSpectators = 0;
                SFSRoomVariable roomVariableStart = new SFSRoomVariable("gameStarted", false);
                roomVariableStart.IsPersistent = true;                                           
                settings.Variables.Add(roomVariableStart);               
                settings.Extension = new RoomExtension(EXTENSION_ID, EXTENSION_CLASS);
                sfs.Send(new CreateRoomRequest(settings, true, sfs.LastJoinedRoom));


On my extension(server side) if user enter on this room i use this code(USER_JOIN_ROOM event)):

Code: Select all

 Room room=(Room) event.getParameter(SFSEventParam.ROOM); 
        if(room.isGame()){         
           SFSRoomVariable startGame=new SFSRoomVariable("gameStarted", true);
            startGame.setGlobal(true);
            startGame.setPersistent(true);
            if(room.getMaxUsers()==room.getUserList().size())   {
                 room.setVariable(startGame);                 
            }


In client side i show all button of the games, but if rooms[i].GetVariable("gameStarted").GetBoolValue()) --->If game is started, i dont want istanciate the button.
I see that only one user see the value gameStarted true(only the last user that enter inside the room), the other instead see the value false.

Inside the zone monitor i see the room variable gameStarted true, persistent and global and with true value when the room is full, but in client side only one see the value true.

Can you help me?
near
Posts: 6
Joined: 05 May 2016, 15:56

Re: Global Room variable

Postby near » 09 May 2016, 16:00

Ok. i have resolved this problem.
I use in server side getApi().setRoomVariables and all users now see the value true when it changes.
thanks anyway.
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Global Room variable

Postby Lapo » 09 May 2016, 16:47

That's correct. :)
Room.setVariables(...) only applies the change locally to the server but doesn't send an update. SFSApi.setRoomVariables(...) sends updates too.

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 46 guests