Question about joining room with custom properties

Options
Hey guys,
I have a simple question regarding the custom properties. Lets say there are two rooms with different custom properties.
First :
string[] roomPropsInLobby = { "sports", 1 }; Hashtable customRoomProperties = new Hashtable() { { "sports", 1 } };
Second :
string[] roomPropsInLobby = { "movies", 1 }; Hashtable customRoomProperties = new Hashtable() { { "movies", 1 } };

When joining the room, I can set the custom properties - so EITHER I set it to Hashtable expectedCustomRoomProperties = new Hashtable() { { "sports", 1 } }; OR I set it to movies. This way I have to choose if I want to join room with "movies" OR with "sports".

Now, is there a way to do both at the same time? Like, setting the custom properties so that I can join "movies" room AND if it doesnt exist I will automatically join the "sports" room? I would basically like to choose several properties and randomly join a room - if a room with first property doesnt exist, join the room with second property, if that doesnt exists, join the third...etc. Is this possible or not at all? Thanks a lot.

Best Answer

  • JohnTube
    JohnTube ✭✭✭✭✭
    Answer ✓
    Options
    Hi @SamPav,

    You should implement this yourself. Try joining "movies" rooms then if it fails try joining "sports" rooms and if it fails create a room.

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    Answer ✓
    Options
    Hi @SamPav,

    You should implement this yourself. Try joining "movies" rooms then if it fails try joining "sports" rooms and if it fails create a room.
  • SamPav
    Options
    Hm that sounds great. How would you do it though?
    I can imagine this : Hashtable expectedCustomRoomProperties = new Hashtable() { { "movies", 1 } }; JoinRandomRoom(expectedCustomRoomProperties, 2); Then, if it fails I do the same in OnPhotonRandomJoinFailed (with "sports this time"). Then, if it fails...I do what? Thats where I am stuck right now...thank you!
  • SamPav
    Options
    Ok I think it can be done this way - if anyone finds this thread.
    Just make a list with topics of the rooms you want to join, then when you are setting the custom properties, just put first item of the list as the hashtable key. If it fails to find the room, remove the item and called it again > once there is nothing in the list it wont be called.

    void JoinTheRoom () { ExitGames.Client.Photon.Hashtable expectedCustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { roomStrings[0], 1 } }; PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, 2); }

    void OnPhotonRandomJoinFailed() { roomStrings.Remove (roomStrings[0]); if (roomStrings.Count < 0) { ExitGames.Client.Photon.Hashtable expectedCustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { roomStrings[0], 1 } }; PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, 2); } else { // do stuff } }