Get array of "rooms" in loby

I know there is PhotonNetwork.GetRoomList(); but that is RoomInfo and I cant access custom properties with RoomInfo, I need to access one custom property (Map name) here is what I have done, Im using PhotonNetwork.GetRoomList(); right now because I dont know any other way to get a list of rooms:
private RoomInfo[] RoomList;
...
void OnReceivedRoomListUpdate() {
        RoomList = PhotonNetwork.GetRoomList();
    }
...

if (RoomList != null) {
                for (int i = 0; i < RoomList.Length; i++) {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("" + RoomList[i], GUILayout.Width(Screen.width * 0.38f));
                    GUILayout.Label("here is supposed to be the map's name", GUILayout.Width(Screen.width * 0.38f));
                    GUILayout.Label(RoomList[i].playerCount + "/" + RoomList[i].maxPlayers, GUILayout.Width(Screen.width * 0.1f));
                    if (GUILayout.Button("Join", GUILayout.Width(Screen.width * 0.1f))) {
                        PhotonNetwork.JoinRoom(RoomList[i].name);
                        Application.LoadLevel("Map1-Online");
                    }
                    GUILayout.EndHorizontal();
                }
            }

Comments

  • RoomInfo has customProperties property
    It would be something like this in your code: RoomList.customProperties["map"]

    To make lobby expose this property in room list, add property name string ("map") to RoomOptions.customRoomPropertiesForLobby array when calling PhotonNetwork.CreateRoom.
  • vadim wrote:
    RoomInfo has customProperties property
    It would be something like this in your code: RoomList.customProperties["map"]

    To make lobby expose this property in room list, add property name string ("map") to RoomOptions.customRoomPropertiesForLobby array when calling PhotonNetwork.CreateRoom.

    Hi, thanks however I got a problem :roll:

    I tried to do what you said but I think I did it wrong, Im getting a Null reference exception
    RoomOptions CustomOptions;
        string[] Options = {"MapProp"};
    ...
    void Start(){
            CustomOptions.customRoomPropertiesForLobby = Options;
        
        }
    ...
    
    void MatchWindowFunc(int id) {
            PlayerName = GUILayout.TextField(PlayerName);
            if (PhotonNetwork.room == null) {
                // Create Room
                if (!PhotonNetwork.connected) {
                    GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
                }
                if (GUILayout.Button("Start Server")) {
                    PhotonNetwork.CreateRoom(RoomName + System.Guid.NewGuid().ToString("N"),CustomOptions,null);
                    Application.LoadLevel("Map1-Online");
                }
            }
    
    
        }
    
    

    The null reference exeption is in the following line:
    void Start(){
            CustomOptions.customRoomPropertiesForLobby = Options;
        
        }
    

    Also unrelated to the CustomOptions error my OnJoinedRoom() its not firing when I create the room (the same code runs fine in the Loby which is separated from the match making menu)
    void OnJoinedRoom() {
            Debug.Log("Connected to Room");
            GameObject _Player = PhotonNetwork.Instantiate(Player.name, Vector3.up * 5, Quaternion.identity, 0);
            _Camera = Camera.main;
            _Camera.GetComponent<CameraScript>().Player = _Player.GetComponent<PlayerProfile>().PlayerCharacter;
            _Camera.GetComponent<CameraScript>().enabled = true;
            _Player.GetComponent<PlayerProfile>().PlayerID = _Player.GetComponent<PhotonView>().ownerId;
            PhotonNetwork.playerName = PlayerName;
        }
    

    Player its not getting instantiated
  • Uninitialized CustomOptions fires Null reference exception.

    OnJoinedRoom get called only if it's part of script attached to the object in scene with PhotonView attached. Make sure that this is true at join/create time.
  • Ok thank you but I got another problem, when I try to get the room's custom map property it gives me an error, when I try to use it in Debug.log it also gives me the same error message.

    This is what I did
    GUILayout.Label("" + xGraphicsManager.Instance.Stages[(int)_NetWorkManager.RoomList[i].customProperties["MapProp"]], GUILayout.Width(Screen.width * 0.38f));
    

    xGraphicsManager.Instance.Stages[] holds all the map's names (strings) in a array, the map property is an int, and this is the code I used to create the room:
    if (GUILayout.Button("Start Server")) {
                    RoomOptions CustomOptions = new RoomOptions();
                    CustomOptions.maxPlayers = 4;
                    CustomOptions.isVisible = VisibleMatch;
                    CustomOptions.isOpen = OpenMatch;
                    CustomOptions.customRoomProperties = new ExitGames.Client.Photon.Hashtable() {{ "MapProp", Map },{"MaxFrags", MaxFrags}};
                    CustomOptions.customRoomPropertiesForLobby = new string[] { "MapProp" };
                    PhotonNetwork.CreateRoom(RoomName, CustomOptions, null);
                }
    

    I dont understand whats wrong with it
  • It's impossible to guess which of your variables is null in line you posted.
    Log each value one by one and you will see.
  • vadim wrote:
    It's impossible to guess which of your variables is null in line you posted.
    Log each value one by one and you will see.

    None of them are null I simply cant access the custom property "MapProp", it isnt listen on loby.

    I did
    CustomOptions.customRoomProperties = new ExitGames.Client.Photon.Hashtable() {{ "MapProp", Map },{"MaxFrags", MaxFrags}};
                    CustomOptions.customRoomPropertiesForLobby = new string[] { "MapProp" };
    

    And tried to access it by using
    (int)_NetWorkManager.RoomList[i].customProperties["MapProp"]
    
  • You wrote that have same error as before. The previous error you reported was null reference.

    I can't see what's inside _NetWorkManager.RoomList

    Iterate PhotonNetwork.GetRoomList() while you are in lobby. It should return rooms created by other clients with properties including "MapProp".
    CustomOptions looks set up properly for that.
  • Ok, here it is, I just have to comment that line since I already iterate through the rooms anyways

    Direct link to image http://imageshack.com/a/img538/2125/xgQLdu.png
    xgQLdu.png
  • Again, print contents of every room in PhotonNetwork.GetRoomList() (probably with room.ToStringFull)
    I don't see how the picture can help with debugging.
    Btw, what value for "map" property you set when creating the room? Log it as well to make sure that it set properly.
    And finally log joined room properties on clients after join or creation: PhotonNetwork.room.ToStringFull()