- Home /
Photon network won't join random room with a custom property
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();
Answer by KLFzx · Jul 20, 2020 at 03:30 PM
@bhavinbhai2707 finally fund the solution bro. these guys from photon are nеr d s. create room function should be like this and battle function is the one which tries to join room with the needed custom propreties.
public void Create()
{
ExitGames.Client.Photon.Hashtable customPropreties = new ExitGames.Client.Photon.Hashtable();
customPropreties["Scene"] = selectedMap.name;
RoomOptions roomOptions = new RoomOptions() {CustomRoomProperties = customPropreties, IsVisible = true, IsOpen = true, MaxPlayers = (byte)roomSize, CleanupCacheOnLeave = false };
roomOptions.CustomRoomPropertiesForLobby = new string[]
{
"Scene",
};
PhotonNetwork.CreateRoom(roomName.text + Random.Range(0, 1000), roomOptions);
}
public void Battle()
{
ExitGames.Client.Photon.Hashtable customPropreties = new ExitGames.Client.Photon.Hashtable();
customPropreties["Scene"] = selectedMap.name;
PhotonNetwork.JoinRandomRoom(customPropreties,0);
}
damn, this was hard. hope I helped someone. please, subscribe to my youtube channel if this was helpful, I release some dope content there: [link text][1] [1]: https://www.youtube.com/channel/UCNzRJ1y_HA-e_mFrhZQEeBw?view_as=subscriber
thank you very much, this really solved the problem. I didn't find that solution although I searched in many pages. thanks again KLFzx
I have this error now: JoinRandomRoom failed. Client is on GameServer (must be $$anonymous$$aster Server for matchmaking) and ready. Wait for callback: OnJoinedLobby or OnConnectedTo$$anonymous$$aster.
Bless your soul, I've been searching everywhere and trying everything to get this to work... even in their own documentation there is no mention of creating the custom variables in the way you did.. and thats the only way that works.. THANK YOU <3
Dude you're a life saver. I was finally able to do it. Thanks!
Answer by JohnnieDyer · Apr 20 at 04:56 PM
Thanks man. I couldnt figure out why this wasnt working. i think it was adding this that made it work:
roomOptions.CustomRoomPropertiesForLobby = new string[]
{
"Scene",
};