Matchmaking Custom Room Properties, multiple game modes?

Options
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!
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);
	}
}

Comments

  • DandS
    Options
    Hi, I know it's been a while but i'm just getting on this same problem myself.

    I think you got the way the custom room properties work wrong. if i am correct about this, when you search for a random room with custom properties, Photon will only join a room that matches ALL the properties you pass, so if you search for a random Room using custom properties with two different game modes ( like Race and BallonFight or whatever) since no room can match both game modes at once, you will never find a suitable room... I think that's the way it works... And that is actually quite annoying in our case...

    If anyone knows any easy way to do this random search with multiple game modes, that would be great!
    For now i just get the list of rooms from the lobby and check every room to see if one of them fits and put them in a list, then i try to join the first room in the list, if joining fails i try the next rooms in the list and if i fail at joining all rooms or if there's no rooms in the list at all, i create one with settings chosen at random from the players choices. This feels really clunky to me ( especially if there is a lot of rooms, just in case my game gets some attention you know... "cough cough") and i hope there is a better way of doing this.

    have a nice day =D