CustomRoomPropertiesForLobby is not working
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).
CustomRoomPropertiesForLobby is not working
AT1LLA
2017-02-19 10:36:04
Here is how i create my room:
public void CreateRoom(){
LobbyOptions = new string[2];
LobbyOptions[0] = MapIndex;
LobbyOptions[1] = GameModeIndex;
RoomOptions roomOptions = new RoomOptions();
roomOptions.IsVisible = true;
roomOptions.IsOpen = true;
roomOptions.MaxPlayers = (byte)MaxPlayersIndex;
roomOptions.CustomRoomPropertiesForLobby = LobbyOptions;
PhotonNetwork.CreateRoom(roomName, roomOptions, TypedLobby.Default);
}
Here is how I get my rooms:
public override void OnReceivedRoomListUpdate()
{
Debug.Log("GET ROOMS: " + PhotonNetwork.GetRoomList().Length);
foreach (RoomJoiner roomButton in rooms)
{
Destroy(roomButton.gameObject);
}
rooms.Clear();
int i = 0;
foreach (RoomInfo room in PhotonNetwork.GetRoomList())
{
if (!room.open)
continue;
GameObject roomButton = Instantiate(roomButtonPrefab);
roomButton.GetComponent().RoomName = room.name;
string info = room.name.Trim() + " (" + room.playerCount + "/" + room.maxPlayers + ")";
Debug.Log(info);
Debug.Log("room.CustomProperties.Count " + room.CustomProperties.Count);
roomButton.GetComponentInChildren().text = info;
rooms.Add(roomButton.GetComponent());
roomButton.transform.SetParent(ServerListPanel, false);
roomButton.transform.position.Set(0, i * 120, 0);
}
}
CONSOLE
room.CustomProperties.Count 0
Am I doing something wrong? Thanks.
Comments
Hi @AT1LLA,
Thank you for choosing Photon!
Please try setting values to those custom room properties when creating the room.
ExitGames.Client.Photon.Hashtable roomSettings = new ExitGames.Client.Photon.Hashtable() {
{ MapIndex, mapIndex }, { GameModeIndex, gameModeIndex }
};
roomOptions.CustomRoomProperties = roomSettings;
Hi @JohnTube ,
Sorry I didn't explained myself. I want to create a lobby. I will have some string variables like GameMode and Map. I want to show them in lobby. I tried your script but it didnt work. I tried
roomOptions.CustomRoomProperties = new string[] { "1", "2", "3" };
just to test but it alse didnt work. I think my problem is hov i get the values.
I do
Debug.Log("room.CustomProperties.Count " + room.CustomProperties.Count);
as the sctipt i posted. Thank you for your answer.
Did you try merging my suggestion with your code?
Room properties are key/values where keys are strings.
Something like this:
public void CreateRoom(){
LobbyOptions = new string[2];
LobbyOptions[0] = MapIndexKey;
LobbyOptions[1] = GameModeIndexKey;
ExitGames.Client.Photon.Hashtable customProperties = new ExitGames.Client.Photon.Hashtable() {
{ MapIndexKey, mapIndexValue }, { GameModeIndexKey, gameModeIndexValue }
};
RoomOptions roomOptions = new RoomOptions();
roomOptions.IsVisible = true;
roomOptions.IsOpen = true;
roomOptions.MaxPlayers = (byte)MaxPlayersIndex;
roomOptions.CustomRoomPropertiesForLobby = LobbyOptions;
roomOptions.CustomRoomProperties = customProperties;
PhotonNetwork.CreateRoom(roomName, roomOptions, TypedLobby.Default);
}
Oh, I did it thank you :smile:
Back to top