Photon network won't join random room with a custom property

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

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).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Photon network won't join random room with a custom property

bhavin2707
2020-04-15 22:25:36

I am creating a multiplayer chess game. The user can play online matches by placing a bet of a certain amount (suppose 500,1000,1500 etc). The user will be placed only against a place who is searching for same bet amount match. I am creating a room with custom properties set as

private void CreateRoom()  
    {  
        Debug.Log("Creating Room Now");  
        int randomRoomNumber = Random.Range(0, 10000);

        int bet = MenuHandler.instance.betAmount;  
        if (bet < 500)  
            bet = 500;

        RoomOptions roomOps = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = (byte)roomSize, CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "Bet", bet } } };


        PhotonNetwork.CreateRoom("Room" + randomRoomNumber, roomOps);

        Debug.Log(randomRoomNumber);   
    }

obviously it will create a room if no similar room exists and join the player 1.

so now, Player 1 is in the room. Now, For player 2 to join the room,

 int bet = MenuHandler.instance.betAmount;  
        if (bet < 500)  
            bet = 500;

        Hashtable expectedCustomRoomProperties = new Hashtable() { { "Bet", bet } };  
        PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, (byte)roomSize);

But, it won't connect player 2 to the room of player 1 at all. It creates its own room (as OnJoinRoomFailed creates the room if it doesn't exist).

I am really not sure what's wrong here. I checked the documentation and everything! this is how they have done it too. Can someone please help me out here?

PS: I have run debugs and the bet amounts are right and being set properly. They just won't connect to the same room.

Debug from the phone:- Joined Room4068 with Bet of (System.String)Bet=(System.Int32)1500, (System.String)curScn=(System.String)RoomWaitingRoom

Debug from the Unity editor:- Joined Room9945 with Bet of (System.String)Bet=(System.Int32)1500

I am running one instance from the phone and second instance on the Unity editor and playing one instance on phone and second is not a problem I think because they connect successfully if I just put JoinRandomRoom();

Comments

S_Oliver
2020-04-16 07:14:44

Hi im not 100% sure about this but i think in RoomOptions you also have to set which Room Properties are visible to the Lobby.

Like

		RoomOptions roomOps = new RoomOptions()  
		{  
			IsVisible = true,  
			IsOpen = true,  
			MaxPlayers = (byte)roomSize,  
			CustomRoomProperties = new ExitGames.Client.Photon.Hashtable()  
			{  
				{ "Bet", bet }  
			},  
			CustomRoomPropertiesForLobby = new[] {"Bet"}  
		};  

With this line the property Bet is know visible in a lobby.

CustomRoomPropertiesForLobby = new[] {"Bet"}
Back to top