Getting Updated Variables on Room

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

Moderators: Lapo, Bax

User avatar
pogsdbest
Posts: 17
Joined: 08 Feb 2019, 10:09

Getting Updated Variables on Room

Postby pogsdbest » 11 Feb 2019, 08:49

Hi, i would like to ask if is there a way to get the updated Room Variables value of a Room
i tried creating a Room in Unity with this Code

Code: Select all

RoomSettings settings = new RoomSettings ( NAME );
        settings.GroupId = "table";
        settings.IsGame = true;
        settings.MaxUsers = 999;
        settings.MaxSpectators = 0;
        settings.MaxVariables = (short)(20);
        List<RoomVariable> variables = new List<RoomVariable> ();
        variables.Add (new SFSRoomVariable("p1", p1 )) ;
        variables.Add ( new SFSRoomVariable("p2", p2 )) ;

And Getting its value by calling

Code: Select all

List<Room> roomList = sfs.GetRoomListFromGroup ( "table" );
for(int i = 0; i < rooms.Count; i++) {
    string p1= rooms[i].GetVariable ( "p1" ).GetStringValue();
        string p2= rooms[i].GetVariable ( "p2" ).GetStringValue ();
        }


on my server java code i am modifying the value of p1and p2 by

Code: Select all

getParentRoom().setVariable(new SFSRoomVariable( "p1",newP1));
getParentRoom().setVariable(new SFSRoomVariable( "p2",newP2));

i also set my RoomVariables to GLOBAL.

but calling GetRoomList with GetVariable doesnt give me the updated value, only the initial value.
am i missing something? thanks
User avatar
pogsdbest
Posts: 17
Joined: 08 Feb 2019, 10:09

Re: Getting Updated Variables on Room

Postby pogsdbest » 11 Feb 2019, 09:40

nevermind i figure it out
this code is not enough to change RoomVariable from the server to client.

Code: Select all

getParentRoom().setVariable(new SFSRoomVariable( "p1",newP1));
getParentRoom().setVariable(new SFSRoomVariable( "p2",newP2));


I need to Call this code, whenever i change Room Variables from the server to update my client.

Code: Select all

getApi().setRoomVariables(null, getParentRoom(), getParentRoom().getVariables());


now RoomList returns the updated value.

Code: Select all

string p1 = rooms[i].GetVariable ( "p1" ).GetStringValue ();
string p2 = rooms[i].GetVariable ( "p2" ).GetStringValue ();
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Getting Updated Variables on Room

Postby Lapo » 11 Feb 2019, 10:23

Yes, that's correct. Calling Room.serVariable() updates the variable locally on the server but does not trigger the necessary updates for all interested clients.

All of the API calls that generate updates for the client are exposed by the SFS2XApi class, accessible via the getApi() method.

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

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 54 guests