GetRoomList not working
Options
Hello,
Today I was trying to getRoomList but it's not working
I make If the room exist then make another room but its not work , it give me it's doesn't exist and when make a room give me error " Operation failed: OperationResponse 227: ReturnCode: 32766 (A game with the specified id already exist.). Parameters: {} Server: MasterServer "
this is the code
Today I was trying to getRoomList but it's not working
I make If the room exist then make another room but its not work , it give me it's doesn't exist and when make a room give me error " Operation failed: OperationResponse 227: ReturnCode: 32766 (A game with the specified id already exist.). Parameters: {} Server: MasterServer "
this is the code
private void RoomCheck(string CheckName , string ElseName) { OnReceivedRoomListUpdate(); List<RoomInfo> roomList = PhotonNetwork.GetRoomList().ToList(); RoomInfo room = roomList.FirstOrDefault(r => r.Name == CheckName); bool exists = (room != null); Debug.Log(exists); if (exists == false ) { var RoomOptions = new RoomOptions {MaxPlayers = 1 , IsOpen = true , isVisible = true}; PhotonNetwork.CreateRoom(CheckName,RoomOptions,null); } else if (exists == true) { var RoomOptions = new RoomOptions {MaxPlayers = 1 , IsOpen = true , isVisible = true}; PhotonNetwork.CreateRoom(ElseName,RoomOptions,null); } }and this is OnReceivedRoomListUpdate
public override void OnReceivedRoomListUpdate() { List<RoomInfo> roomList = PhotonNetwork.GetRoomList().ToList(); }
0
Comments
-
Hi @Anteeiiku,
Thank you for choosing Photon!
We do not recommend this approach.
Why do you need to create rooms with a specific name?
What we recommend is:
Try to find a room matching the criteria you want, if not found, create a new one.
Giving an explicit name to a room is optional.
Besides,PhotonNetwork.GetRoomList()
should give correct result (cached rooms list) after theOnReceivedRoomListUpdate()
callback is triggered automatically by PUN (and not explicitly called by your code like in your example). That is why we usually recommend usingPhotonNetwork.GetRoomList()
inside the callback itself.1 -
But I have question , If I have 5 Rooms and I wanna to check room number 3 isn't open
How I can do this ?0 -
Hi @Anteeiiku,
You need to keep a cached updated list of rooms in the lobby.
Get the room by index or name and check it'sRoomInfo.IsOpen
to know if it's open or not.0