I'm not sure if I'm thinking about how Custom Room Properties works the wrong way or not, but maybe someone can help me out. This is how I'm trying to implement them:
1. The player chooses which game modes to search for by checking the boxes next to each one they want to play.
2. When the player presses PLAY, a hashtable is created with the selected game modes: {{"mode1", "true"},{"mode2","false"},...}
3. PUN looks for an open room with one of the desired modes set to true.
4A. If no room is found, create on with one of the desired game modes (chosen randomly).
4B. If a room is found, join it.
Right now, creating the room from the desired list works fine, but I can't seem to find a room with the custom options I've set. I think I'm searching the filters incorrectly, where what I need is to find any room that has a matching game mode set to true. I think I'm just hung up on the way I'm approaching it and I need another perspective. Thank you!
1. The player chooses which game modes to search for by checking the boxes next to each one they want to play.
2. When the player presses PLAY, a hashtable is created with the selected game modes: {{"mode1", "true"},{"mode2","false"},...}
3. PUN looks for an open room with one of the desired modes set to true.
4A. If no room is found, create on with one of the desired game modes (chosen randomly).
4B. If a room is found, join it.
Right now, creating the room from the desired list works fine, but I can't seem to find a room with the custom options I've set. I think I'm searching the filters incorrectly, where what I need is to find any room that has a matching game mode set to true. I think I'm just hung up on the way I'm approaching it and I need another perspective. Thank you!
RoomJoin() {
if (PhotonNetwork.insideLobby) {
//Custom Room Properties Hashtable
ExitGames.Client.Photon.Hashtable table = new ExitGames.Client.Photon.Hashtable ();
//Room options strings
List<string> selectedModes = new List<string>();
for(int i = 0; i < modes.Length; i++)
{
if (modes [i].selected) {
table.Add (modes [i].gameObject.name, modes [i].selected.ToString ());
selectedModes.Add (modes [i].gameObject.name);
}
}
m_roomOptions = new RoomOptions ();
m_roomOptions.CustomRoomPropertiesForLobby = selectedModes.ToArray();
m_roomOptions.CustomRoomProperties = table;
m_roomOptions.MaxPlayers = 99;
PhotonNetwork.JoinRandomRoom (table, 0);
}
}
public void CreateNewRoom()
{
//Custom Room Properties Hashtable, remove unwanted modes
ExitGames.Client.Photon.Hashtable table = m_roomOptions.CustomRoomProperties;
List<string> selectedModes = new List<string> ();
//Debug
string list = "";
foreach (DictionaryEntry e in table) {
if (e.Value.ToString() == "false") {
table.Remove (e);
} else {
selectedModes.Add (e.Key.ToString());
list += e.Key.ToString () + ", ";
}
}
print (list);
//Now choose random mode from list
string[] selected = {selectedModes[Random.Range(0,selectedModes.Count)]};
table.Clear ();
table.Add (selected, "true");
m_roomOptions.CustomRoomPropertiesForLobby = selected;
m_roomOptions.CustomRoomProperties = table;
m_roomOptions.MaxPlayers = 6;
print("Creating room: " + selected[0]);
PhotonNetwork.CreateRoom (null, m_roomOptions, null);
}
}