GetRoomList() only working when called from OnReceiveRoomListUpdate()

Hi,

I have been using photon for a while and I'm really liking it. I never used multiple rooms in my prototypes until today(just joined a random room etc), and while creating the UI for the lobby I tried to call GetRoomInfo() from OnJoinedLobby(). It always returned an empty RoomInfo[] even if I knew there were rooms available.

After a quick google search I learned that the only way to get meaningful data from GetRoomInfo() is to call it from OnReceivedRoomListUpdate() (???)

I do not mind the fact that you can only access that info from that callback, the thing that left me wandering is why you decided to make GetRoomList() a public static. I spent ten minutes changing the callback in NetworkPeer to send the RoomList[] as a parameter for OnReceivedRoomListUpdate. Is there any reason why it was not built like this in the first place? I saw some confusion online regarding this call and it could be easily avoided.

Cheers!

Comments

  • Hi @DWR,

    [...] I tried to call GetRoomInfo() from OnJoinedLobby(). It always returned an empty RoomInfo[] even if I knew there were rooms available.


    The problem is that the local client's room list is not updated and therefore not immediately available after joining the lobby. This is the reason why there is OnReceivedRoomListUpdate. When this callback gets processed you know, that there has been an update and that you can call GetRoomList() again. If this still returns an empty room list there is no room available, otherwise you can iterate through the room list and get all the RoomInfos.

    [...] I learned that the only way to get meaningful data from GetRoomInfo() is to call it from OnReceivedRoomListUpdate()


    Well, it depends. You can directly call GetRoomList from OnReceivedRoomListUpdate to somehow update the visualization of the available rooms. But you can also add a bool for example which tells you that you have received a room list update and call GetRoomList from another place. By GetRoomInfo I guess you mean GetRoomList, don't you?

    [...] why you decided to make GetRoomList() a public static.


    Well I don't know if this is the 'official' reason, but in my opinion it is public static in order to call it from everywhere so that you don't need a reference or similar to get the room list. It's basically the same with all other function calls in PhotonNetwork class, see Instantiate for example.
  • Well I don't know if this is the 'official' reason, but in my opinion it is public static in order to call it from everywhere so that you don't need a reference or similar to get the room list. It's basically the same with all other function calls in PhotonNetwork class, see Instantiate for example.

    This is what I find weird. If I can call a method from anywhere, I expect to have his return value from anywhere (or some kind of error value if it is not available). If the value is only available during a specific callback, just pass it as a parameter for that callback and then let me do what I want with it.

    Maybe I'm just being fussy.

    Thanks for the answer anyway :)