Some questions: Custom room and player properties. Sync some info in room. Set Room closed.

Options
Hello! I'm novice in Photon but not novice in Unity.
I have some questions
1.How can I add custom properties to room and get it?
I was trying it:
RoomOptions roomOptions = new RoomOptions();
        roomOptions.CustomRoomProperties.Add("test", "simple");
        PhotonNetwork.CreateRoom("text okay", roomOptions, null);
Idk works it or no, but problem it's I can't get this key! How I should?

I have a waiting room before starting the game... So there 2 questions:
2. How can I sync some infos. Like a integer, toggle(checkbox).
3. How can I remove lobby from visible after scene loading(GameStarting)

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2017
    Options
    Hi @RandomMan,

    Thank you for choosing Photon and here is a not so random answer:

    To get room properties after you join the room:
    string exampleValue = PhotonNetwork.room.customProperties["test"];
    
    To set custom room properties:
    PhotonNetwork.room.SetCustomProperties(hashtable);
    
    To close a room:
    PhotonNetwork.room.IsOpen = false;
    
    To make a room invisible inside the lobby:
    PhotonNetwork.room.IsVisible = false;
  • RandomMan
    Options
    I need to set custom properties when CreatingRoom, how is it possible using RoomOptions?
    And Need get in lobby, like a room name etc...

    Also thanks for Close answer, I think it need!

    and I still don't know how to sync some checkboxes or infos players in room! (they will edit it in room)
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2017
    Options
    I can't understand your question:

    Do you want to set custom room properties during creation, you're already doing it right:
    RoomOptions roomOptions = new RoomOptions();
    roomOptions.CustomRoomProperties = new Hashtable() {{"test", "sample"}};
    PhotonNetwork.CreateRoom("text okay", roomOptions, null);
    Do you want to set custom room properties visible from the lobby during creation:
    you just need to add their keys to RoomOptions.CustomRoomPropertiesForLobby e.g.
    RoomOptions roomOptions = new RoomOptions();
    roomOptions.CustomRoomProperties = new Hashtable() {{"test", "sample"}};
    roomOptions.CustomRoomPropertiesForLobby = new string[] {"test"};
    PhotonNetwork.CreateRoom("text okay", roomOptions, null);
  • RandomMan
    Options
    JohnTube said:

    I can't understand your question:

    RoomOptions roomOptions = new RoomOptions();
    roomOptions.CustomRoomProperties = new Hashtable() {{"test", "sample"}};
    PhotonNetwork.CreateRoom("text okay", roomOptions, null);
    I think thats what I need!

  • RandomMan
    Options
    But still question. How to sync player infos? Is possible to add to Player also CustomProperties like a level and get it?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2017
    Options
    please use:
    photonPlayer.SetCustomProperties(hashtable);
    
    to get local player:
    PhotonNetwork.player
    there are multiple ways to get other players, e.g.
    photonPlayer = PhotonPlayer.Get(actorNr);
  • RandomMan
    RandomMan
    edited January 2017
    Options
    Okay. How can I know actorNr?

    And now I found, That I can't get CustomProperties! I trying
     roomsList = PhotonNetwork.GetRoomList();
            for (int i = 0; i < roomsList.Length; i++)
            {
                GameObject go = Instantiate(Resources.Load("RoomLine", typeof(GameObject)), RoomsPlace.transform) as GameObject;
              go.transform.FindChild("RoomName").GetComponent<Text>().text = roomsList[i].Name;//That's works
                go.transform.FindChild("TestElement").GetComponent<Text>().text = roomsList[i].CustomProperties["test"]; //That's not!
            }
    
    And there I get error cannot convert type object to string.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    As I told you there are different ways to get players, e.g.
    • PhotonPlayer.GetNext()
    • PhotonPlayer.GetNextFor()
    • PhotonNetwork.otherPlayers
    • PhotonNetwork.playerList // all players including local one
    You need to make some custom properties visible to the lobby.
    roomOptions.CustomRoomPropertiesForLobby = new string[] {"test"};

  • RandomMan
    Options
    But I did it visible! It still says can't convert object to string because here I save it like string and get like an Object. Why?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    You just need a cast from object to string:
    string stringValue = roomOrRoomInfo.CustomProperties["test"] as string;
    textUiComponent.text = stringValue;