Getting RoomInfo.customProperties in Lobby

Options
Hi I'm trying to figure out why in the lobby I'm having trouble grabbing the customProperties of the rooms that are created.

On the room's creation, it sets the hashtable value "levelName" to Application.loadedLevelName. And when other players join the room, they can see the variable just fine through PhotonNetwork.room.customProperties["levelName"].ToString()

I set it like this and it reads just fine when another player joins the room.
if(PhotonNetwork.isMasterClient)
       {
        h = new Hashtable();
        h.Add("levelName", Application.loadedLevelName);
      
        PhotonNetwork.room.SetCustomProperties(h);
       }

But in the lobby when I ask for the RoomInfo.customProperties is says it's length is 0 and "levelName" doesn't exist.
foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList())
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(roomInfo.name + " " + roomInfo.playerCount + "/" + roomInfo.maxPlayers +" / "+roomInfo.customProperties.Count);
                
                if (roomInfo.customProperties.ContainsKey("levelName"))
                {
                Debug.Log("found levelName");
                GUILayout.Label(roomInfo.customProperties["levelName"].ToString());//.ToString());
                }
                
                if (GUILayout.Button("JOIN"))
                {
                    PhotonNetwork.JoinRoom(roomInfo.name);
                }
}

I'm not sure if I'm trying to get this data the wrong way or if I'm setting it the wrong way.

Comments

  • Tobias
    Options
    We don't send all properties to the lobby anymore.

    In 1.9 we added a string[] to CreateRoom which let's you chose which custom props are also updated in the lobby. This way, you can have a much bigger amount of props in the room while keeping the lobby's room listing lean.

    Check the overloads of CreateRoom for propsToListInLobby.
  • rstorm000
    Options
    Yeah, thank you, I just figured this out last night. I used this command when creating the room.


    h = new Hashtable();
            h.Add("levelName", chosenLevel);
             ss = new string[2];
           ss[0] = "levelName";
           ss[1] = "gameType";
    
            PhotonNetwork.CreateRoom(chosenLevel, true, true, 10, h,ss );
    

    h is the hashtable that contains the special properties. but ss is the import string[] you were talking about that determines what properties you see while in the lobby. Hope this helps anyone!
  • dreamora
    Options
    Very nice addition and with the integration of real properties more than welcome and needed :)
  • rstorm000
    Options
    Yeah it's nice because you can set the properties from within the game itself using something like...
    if(PhotonNetwork.isMasterClient)
           {
            hm = new Hashtable();
            hm.Add("gameType", "CTF");
          
            PhotonNetwork.room.SetCustomProperties(hm);
           }
    

    This will change the "gameType" variable in the customProperties to CTF while you are inside the server (not during the CreateRoom function). Although I'm not sure how hashtables work, like would this destroy or replace "gameType" if it already had a value. My guess is that it does.
  • dreamora
    Options
    you will get an exception when you use add and its already present in the hashtable as dictionaries in general don't allow dublicates, be it dictionary<,>, hashset or hashtable :)

    You would want to use hm["gameType"] = "CTF" to either set or replace it.
  • tutibueno
    Options
    Guys,

    How do I get the lobby custom properties of a certain room to show in the room list? Can one of you give me an example? I really can't figure it out... thanks!
  • Tobias
    Options
    tutibueno:

    The solution is already posted above:
    [code2=csharp]customRoomPropertiesToSet = new Hashtable();
    customRoomPropertiesToSet.Add("levelName", chosenLevel);
    customPropertiesForLobby = new string[2];
    customPropertiesForLobby[0] = "levelName";
    customPropertiesForLobby[1] = "gameType";

    PhotonNetwork.CreateRoom(chosenLevel, true, true, 10, customRoomPropertiesToSet, customPropertiesForLobby );[/code2]

    Any property name that goes into the lobby should be really short (use "l" instead of "levelName", "g" instead of "gameType", etc), as this is going to be sent to a lot of clients a lot of times.
    In the lobby you get RoomInfo objects and those contain a CustomProperties Hashtable which will contain "l". If "g" ever gets a value in this room, this will also become available (even if set later on).

    See also:
    http://doc.exitgames.com/photon-cloud/M ... references
  • tutibueno
    Options
    Thanks Tobias!

    Now I figured it out! I really missed the point of what goes to the "lobby properties" is exactly part of the hash table that you create for the custom properties. I thought it was totally independent and would had to update those lobby properties every time I changed leve or game type ;)

    very very cool!!

    In case someone else has the same question as mine. I am posting my test code:

    [code2=csharp]// Create a room (fails if exist!)
    GUILayout.BeginHorizontal();
    GUILayout.Label("CREATE ROOM:", GUILayout.Width(150));
    this.roomName = GUILayout.TextField(this.roomName);
    if (GUILayout.Button("GO"))
    {
    string chosenLevel = "Some Level";
    string gameType = "TDM";

    Hashtable customPropertiesToSet = new Hashtable();
    customPropertiesToSet.Add("l", chosenLevel);
    customPropertiesToSet.Add("t", gameType);

    string[] customPropertiesForLobby = new string[2];
    customPropertiesForLobby[0] = "l";
    customPropertiesForLobby[1] = "t";

    PhotonNetwork.CreateRoom(chosenLevel, true, true, 10, customPropertiesToSet, customPropertiesForLobby);
    }

    GUILayout.EndHorizontal();


    GUILayout.Space(30);
    GUILayout.Label("ROOM LISTING:");
    if (PhotonNetwork.GetRoomList().Length == 0)
    {
    GUILayout.Label("..no games available..");
    }
    else
    {
    // Room listing: simply call GetRoomList: no need to fetch/poll whatever!
    this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
    foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList())
    {
    GUILayout.BeginHorizontal();
    GUILayout.Label(roomInfo.name + " " + roomInfo.playerCount + "/" + roomInfo.maxPlayers + "/" + roomInfo.customProperties["l"] + roomInfo.customProperties["t"]);
    if (GUILayout.Button("JOIN"))
    {
    PhotonNetwork.JoinRoom(roomInfo.name);
    }

    GUILayout.EndHorizontal();
    }

    GUILayout.EndScrollView();
    }

    GUILayout.EndArea();
    }[/code2]
  • So, how can we load new map? with default method?
  • Tobias
    Options
    Acolit: A bit off topic ;)
    You can load a new level with the usual methods but we also implemented a method that will make the remote players load the same map.

    From the changelog.txt (in PUN 1.18):
    "Added: PhotonNetwork.automaticallySyncScene for automatic loading of the correct scenes. Simply join a room and all clients will always open the same scene as the MasterClient. Off by default!"

    Check the description of that property and PhotonNetworking.LoadLevel().
  • Oh, is it a new version of PUN?
    thank you, i'll try it=)
    and have 1 more question: i can't found it in script reference, but how can i create some empty rooms on photon cloud?
  • Tobias
    Options
    You can't create empty rooms. You can create a room but the client doing this will join this room.
    If you absolutely need a list of empty rooms, add it client side. You do have the list of existing rooms from the server. Compare that with a list of rooms you want to show any time and if some of that names is missing, just add it as room with 0 players to the room listing you show.
  • How can i add it clientside? just create with me own?
    i don't have any rooms from the server, just my own rooms, and rooms from other players...
    i mean , how can i create a room with 0 players, i saw some games with this function, or it were games with server?
  • Tobias
    Options
    Again: You can't create a room with 0 players.
    You can only "do as if" and display them in your room list.
    Example: You want room "myRoom" to be listed no matter if empty or not. Your client lists rooms while being in the "lobby" state. Your code checks the room list for "myRoom" and if it's not in there, make a copy of the room list and add "myRoom" to it.
    If a user clicks on "myRoom" to join it, your client silently checks the player count and if it's 0, create the room instead of joining it.
  • Jay_mt
    Jay_mt
    edited April 2017
    Options
    Hello :)

    Is it still possible to get custom lobby properties in the actual version?

    ***********
    EDIT
    ***********

    My bad it work perfectly, i adjusted the code, so the example below work!

    var roomProperties = new ExitGames.Client.Photon.Hashtable();
    roomProperties.Add("creator", Username);

    var roomPropertiesLobby = new string[1];
    roomPropertiesLobby[0] = "creator";

    var ro = new RoomOptions();
    ro.MaxPlayers = maxPlayers;
    ro.CustomRoomProperties = roomProperties;
    ro.CustomRoomPropertiesForLobby = roomPropertiesLobby;
    PhotonNetwork.CreateRoom(roomName, ro, TypedLobby.Default);

    My question is how do you get the room properties in the RoomList?
    var roomInfo = PhotonNetwork.GetRoomList();
    Debug.Log(roomInfo[0].CustomProperties["creator"]);