How to assign specific data for room?

Options
Hallo,

I am a newbie in PUN and first of all I want to excuse my english because I am from germany.

I have just one little question, which you can read in the title. I already made a list of active rooms using "PhotonNetwork.GetRoomList()", but there is one problem: I can only get the data which I defined as roomInfo for the rooms. But I want to show some more data in the "hosted games list" like the specific host name which every user can define or a description of the game.

I have already searched in the internet about custom room properties but I did not really understand how this works (maybe because my english is not that good). I hoped that someone here can help me completing my current code to make it work :x
Or maybe you can explain it to me in an easy way. Both would be great!

Here is my code for hosting a game:
https://www.dropbox.com/s/e4kx1sd7fhsq6m7/Screenshot 2017-04-16 16.12.11.png?dl=0

Here is my code for showing the data in the ui list:
https://www.dropbox.com/s/5wwtk9y9epyydks/Screenshot 2017-04-16 16.12.09.png?dl=0
(the item is the UI-Panel showed in the list)
(the string "Testszen" is just a placeholder for the name of the host)

I thank you in advance for your help!

AniProGuy

Best Answers

Answers

  • Bunzaga
    Options
    Hey AniProGuy, this was a bit confusing for me as well, in spite of the great documentation. Rooms have two different sets of data to define and access what you want.

    The first is the room.CustomRoomProperties. This one is the ExitGames.Client.Photon.Hashtable, where you use a string identifier, along with the object you want as the value.

    For example, you could do:

    ExitGames.Client.Photon.Hashtable roomProperties = new ExitGames.Client.Photon.Hashtable(){{"HostName", "Bunzaga"}, {"Description", "Only enter if you brought some Vodka"}};

    Like JohnTube mentioned, you need to set this on your roomOptions, when you create the room.

    The second set of data, is what we use to tell Photon, what we want to allow people in the lobby (outside of the room) to see. A rooms custom properties could have all kinds of Game State data, and we don't need to share that with everyone who just wants a list of the rooms.

    This is the CustomRoomProperitesForLobby, and this is just a string array, listing the specific 'keys' from our original hashtable...

    string[] lobbyAllowedProperties = new string[]{ "HostName", "Description"};

    That also gets set on your roomOptions.

    So now, when you get your list of rooms, you can parse the (string)room.CustomRoomProperties["HostName"] and the (string)room.CustomRoomProperties["Description"].

    Do note, that in order to change these lists, you need to actually create a new Hashtable or string[], make the changes you want, and re-send it to Photon, you can't just modify the local lists.

    I think that covers everything I have gathered from the documentation and through trial and error, tutorials, etc.
  • AniProGuy
    Options
    Thank you, I will try this! :)

    But I have another question about PhotonNetwork.playerList:

    Why is there no order? When I print all the PhotonPlayer.IDs of the member in a room by the master client, this is the result:
    I join: 1
    2. client joins: 2, 1
    3. client joins: 2, 1, 3
    4. clien joins: 2, 1, 3, 4
    an so on.

    I do not understand this at all o.O
  • AniProGuy
    Options
    @Bunzaga
    I already rad your comment and it was soo helpfull! But than I reloaded the side and it was gone away before I could save it (I tried to copy your comment but is was to late >.<)

    But I think I can remember the important things and now I will try to implement it. Thank you!
  • AniProGuy
    AniProGuy
    edited April 2017
    Options
    I tried to implement it and to get the value of "map" from my client:
    https://www.dropbox.com/s/k96rw44gt22ohdi/Screenshot 2017-04-18 09.32.47.png?dl=0

    But I just got the error:
    NullReferenceException: Object reference not set to an instance of an object
    HostNetworkGameInteraction.OnJoinedRoom () (at Assets/Basic/Scenes/NetworkMenu/Scripts/HostNetworkGameInteraction.cs:31)

    Edit:
    I solved it by myself ^^
    -> PhotonNetwork.room.SetCustomProperties (customData, null, true);

    No, the only problem is, that the error comes when I want to display the name on another client who is not connected to the romm (there is a list of open rooms). Is it not possible to acces the costum properties from outside of the room?

    I use this code:
    room.CustomProperties["map"].ToString()