7

I need to list the romos there are in my lobby scene. For now, this is the code I've used but I don't know why it isnt working. Is this the correct way?

public override void OnRoomListUpdate(List<RoomInfo> roomList)
     {
         print(roomList.Count + " Rooms");
         base.OnRoomListUpdate(roomList);
         foreach (var Item in roomList)
         {
             RoomName = Item.Name;
             PlayerAmount = Item.PlayerCount;
             MaxPlayers = Item.MaxPlayers;
             PhotonNetwork.Instantiate("RoomPrefab", transform.position, transform.rotation);
             RoomPrefab.transform.Find("RoomName").GetComponent<Text>().text = RoomName;
             RoomPrefab.transform.Find("PlayerInt").GetComponent<Text>().text = PlayerAmount.ToString();
             if(MaxPlayers == 4)
             {
                 GameObject.Find("IPlayerA").GetComponent<Image>().sprite = Four;
             }
             else if (MaxPlayers == 2)
             {
                 GameObject.Find("IPlayerA").GetComponent<Image>().sprite = Two;
             }
             else if (MaxPlayers == 3)
             {
                 GameObject.Find("IPlayerA").GetComponent<Image>().sprite = Three;
             }
             RoomPrefab.transform.SetParent(ScrollView.transform, false);
         }
     }

I need to specify that I'm using Photon's PUN2, so GetRoomList won't work.

Sebastián García
  • 103
  • 1
  • 3
  • 11
  • 2
    It is expected that the client doesn't receive any room list updates while he is in a room. You can try to clear the locally stored room list when entering a room or after having joined a room. Later, when leaving the room, the client should receive an up-to-date room list as soon as he has entered the lobby (is connected to the MasterServer) again. -- https://forum.photonengine.com/discussion/12860/pun2-onroomlistupdate-not-called-while-in-room -- can you check out this topic? – Jevgeni Geurtsen Nov 15 '18 at 09:39
  • Please [edit](https://stackoverflow.com/posts/52793933/edit) your question and describe what you mean when you say "it isn't working". Does it fail to compile? Does reaching that code kill the application? There is no way to tell from your question. – Ruzihm Nov 15 '18 at 23:17
  • @JevgeniGeurtsen *> the client should receive an up-to-date room list as soon as he has entered the lobby (is connected to the MasterServer)* I wouldn't say that being connected to the MasterClient automatically means being in the lobby. In my case `OnRoomListUpdate` is called only if I explicitly join the lobby after connecting to the MasterClient. – Serg Oct 07 '19 at 10:57

2 Answers2

2

PhotonNetwork.GetRoomList() is gone in PUN2. You get rooms list and updates from ILobbyCallbacks.OnRoomListUpdate(List roomList) callback. You can optionally cache it, update it and clear it when needed.

Also you can check updates from PUN to PUN2 here https://doc.photonengine.com/en-us/pun/v2/getting-started/migration-notes

1

The OnRoomListUpdate() method is called only when you've explicitly joined the lobby via PhotonNetwork.JoinLobby(). It's not enough just to be connected to the MasterServer as Jevgeni Geurtsen suggested, at least in PUN v2.15 it works this way for me.

Serg
  • 6,742
  • 4
  • 36
  • 54