How to get CustomRoomPropertiesForLobby and CustomRoomProperties ?

Click a button to create room, pass roomOps to PhotonNetwork.CreateRoom,
public void Confirm()
{
        RoomOptions roomOpts = new RoomOptions();
        roomOpts.MaxPlayers = 2;

        roomOpts.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable();
        roomOpts.CustomRoomProperties.Add("GameTime", "120");
        roomOpts.CustomRoomProperties.Add("NumLife", "10");
        roomOpts.CustomRoomPropertiesForLobby = new string[2] { "GameTime", "NumLife"};

        // create a room and join it
        PhotonNetwork.CreateRoom("attp's battle field", roomOpts, null);
}
I want to show GameTime and NumLife in lobby, so try access those properties in callback OnReceivedRoomListUpdate,
    public override void OnReceivedRoomListUpdate()
    {
        // get room list info
        RoomInfo[] roomInfos = PhotonNetwork.GetRoomList();
        RoomListTableViewController roomListCon = GameObject.Find("RoomListTableViewController").GetComponent<RoomListTableViewController>();
        roomListCon.m_numRows = roomInfos.Length;
        if (roomInfos.Length > 0)
        {
            foreach (RoomInfo roomInfo in roomInfos)
            {
                roomListCon.roomNames.Add(roomInfo.name);
                
                // I try access GameTime and NumLife here
            }
        }
    }

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited December 2016
    Hi @attolee,

    The room custom properties visible to the lobby are available in the RoomInfo class: roomInfo.customProperties:

    So you should first add the properties to the lobby ones:
    roomOpts.CustomRoomPropertiesForLobby = new string[2] { "GameTime", "NumLife"};
    
    Then you can do something like this:
    string GameTime = roomInfo.customProperties["GameTime"];
    string NumLife = roomInfo.customProperties["NumLife"];
  • attolee
    attolee
    edited December 2016
    thank you @JohnTube ,

    roomListCon.gameTime.Add((string)roomInfo.customProperties["GameTime"]);
    roomListCon.numLife.Add((string)roomInfo.customProperties["NumLife"]);
    those codes work out.