onRoomListUpdate not updating roomlist properly?
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
onRoomListUpdate not updating roomlist properly?
Howardxu23
2021-11-02 00:02:18
currently I'm trying to create a server list browser, and it relied on onRoomListUpdate() to get the list of rooms. while it works fine when there is only one room on the lobby at a time, but when it no longer exists or a new room from another player is created.
The former keeps the room there even though it knows it does not exist, and said code should not put it there either. Attempting to join the limbo room yields a onjoinroomfailed,32758, game does not exist) The latter seems to "overwite" the previous room panel, making the rest of the code think that there is only one room. I have noted that it fixes itself every time I disconnect from the server and rejoin it, only then it displays correctly for both issues.
code for the override of onroomlistupdate():
public override void OnRoomListUpdate(List<RoomInfo> roomlist)//when the server sends a updated roomlist
{
RoomList = roomlist;
clearRoomList();//clears the old list
roomlistUpdate = true;
Transform listcontent= RoomPanel.transform.Find("Scroll View/Viewport/Content");//finds the scorll menu
Debug.Log("Room count: "+ roomlist.Count);
foreach (RoomInfo oneroomdata in roomlist)
{
if (oneroomdata.IsOpen == true && oneroomdata.IsVisible == true && oneroomdata.RemovedFromList == false)
{
Debug.LogWarning("creating new room panel");
GameObject newRoomPanel = Instantiate(roomInfoItem, listcontent)as GameObject;//creates new room data panel
newRoomPanel.transform.Find("room name").GetComponent<Text>().text = oneroomdata.Name;//sets the name
newRoomPanel.transform.Find("players in room").GetComponent<Text>().text = oneroomdata.PlayerCount + "/" + oneroomdata.MaxPlayers;//sets no. of players in room currently
newRoomPanel.transform.Find("join room Button").GetComponent<Button>().onClick.AddListener(delegate { joinRoom(newRoomPanel.transform); });//allows the button to be used to connect
}
}
base.OnRoomListUpdate(roomlist);
}
Comments
[Deleted User]
2021-11-02 08:03:50
Don't clear the old room list. This is not how it's supposed to be used. OnRoomListUpdate
sends a list of updated rooms. It does not contain every single room in the entire region every time on each send unless you are first joining the lobby, after you get the first dispatch it will only give you updates from then on. RemovedFromList
exists because you are supposed to remove it from the list once it's not there anymore.
public List<RoomInfo> Rooms = new List<RoomInfo>();
public override void OnRoomListUpdate(List<RoomInfo> p_list)
{
base.OnRoomListUpdate(p_list);
foreach (var room in p_list)
{
if (room.RemovedFromList)
{
Rooms.Remove(room);
continue;
}
Rooms.Add(room);
}
}
Howardxu23
2021-11-02 13:03:48
MeepPun 2021-11-02T08:03:50+00:00
Don't clear the old room list. This is not how it's supposed to be used.
OnRoomListUpdate
sends a list of updated rooms. It does not contain every single room in the entire region every time on each send unless you are first joining the lobby, after you get the first dispatch it will only give you updates from then on.RemovedFromList
exists because you are supposed to remove it from the list once it's not there anymore.public List<RoomInfo> Rooms = new List<RoomInfo>(); public override void OnRoomListUpdate(List<RoomInfo> p_list) { base.OnRoomListUpdate(p_list); foreach (var room in p_list) { if (room.RemovedFromList) { Rooms.Remove(room); continue; } Rooms.Add(room); } }
ah the clearing of the old room list is clearing the display on the game side
Howardxu23
2021-11-02 13:28:50
MeepPun 2021-11-02T08:03:50+00:00
Don't clear the old room list. This is not how it's supposed to be used.
OnRoomListUpdate
sends a list of updated rooms. It does not contain every single room in the entire region every time on each send unless you are first joining the lobby, after you get the first dispatch it will only give you updates from then on.RemovedFromList
exists because you are supposed to remove it from the list once it's not there anymore.public List<RoomInfo> Rooms = new List<RoomInfo>(); public override void OnRoomListUpdate(List<RoomInfo> p_list) { base.OnRoomListUpdate(p_list); foreach (var room in p_list) { if (room.RemovedFromList) { Rooms.Remove(room); continue; } Rooms.Add(room); } }
the clearlist is to clear the player's GUI server list panel, and does not do anything to the code
Anyway I modified the code, while it seems to have fixed the rooms being created and destroyed, a new issue pops up.
when a player joins/leaves a created room, the code thinks that a new room is created, so creates a duplicate panel of the same room, instead of updating the previous panel data.
if I try to clear the Roomlist each time before the first foreach then the aftermentioned problem sets in again.
public override void OnRoomListUpdate(List<RoomInfo> p_list)//when the server sends a updated roomlist
{
base.OnRoomListUpdate(p_list);
Transform listcontent= RoomPanel.transform.Find("Scroll View/Viewport/Content");
Debug.Log("P_list count: "+ p_list.Count);
//RoomList = new List<RoomInfo>();
foreach (var oneroomdata in p_list)
{
if(oneroomdata.RemovedFromList == true || oneroomdata.IsOpen == false)
{
RoomList.Remove(oneroomdata);
continue;
}
RoomList.Add(oneroomdata);
}
Debug.Log("roomList count: "+RoomList.Count);
clearRoomList();//clears the old list in display
foreach (var room in RoomList)
{
Debug.LogWarning("creating new room panel");
GameObject newRoomPanel = Instantiate(roomInfoItem, listcontent) as GameObject;//creates new room data panel
newRoomPanel.transform.Find("room name").GetComponent<Text>().text = room.Name;//sets the name
newRoomPanel.transform.Find("players in room").GetComponent<Text>().text = room.PlayerCount + "/" + room.MaxPlayers;//sets no. of players in room currently
newRoomPanel.transform.Find("join room Button").GetComponent<Button>().onClick.AddListener(delegate { joinRoom(newRoomPanel.transform); });//allows the button to be used to connect
}
}
Howardxu23
2021-11-02 17:07:53
so do I need to look for the old room's name and update other details in it, say I have a player amount displayed as well, have the code match the room's name and then update the value of it?
Back to top