[PUN] customProperties[key] where value is a string

Hi !

I got that code:

    void DrawPartiesList(string search)
    {
        ClearPartiesList();
        foreach (RoomInfo party in PhotonNetwork.GetRoomList())
        {
            string password = party.customProperties["pwd"];

            if (password != "")
            {
                Image privateRoom = listItem.GetComponent<Image>();
                privateRoom.gameObject.SetActive(true);
            }
        }
    }

Everything works fine but

says that I can’t convert object to string …

When I create the custom property like:

options = new RoomOptions();
options.MaxPlayers = 4;
options.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "pwd", partyPwd } };
foreach (var key in options.CustomRoomProperties.Keys)
{
    Debug.Log(key + ": " + options.CustomRoomProperties[key] + " of type " + options.CustomRoomProperties[key].GetType());
}

the log returns:

I don’t get it !

EDIT:

Ok, I found out that

is null …

But since i setted it I don’t understand :frowning:

On one you have customProperties and on the other you have CustomRoomProperties – are you sure you’re setting / checking the right fields?

1 Like

OMG Yes

— Applying changes —

Ok, theres still a problem:

void Start () {
        PhotonNetwork.autoJoinLobby = true;
        partyName = GameObject.Find("Party Name InputField Text").GetComponent<Text>().text;
        partyPwd = GameObject.Find("Party Password InputField Text").GetComponent<Text>().text;
        options = new RoomOptions();
        options.MaxPlayers = 4;
        PhotonNetwork.ConnectUsingSettings(_gameVersion);
    }  

void OnJoinedLobby()
    {
        PhotonNetwork.CreateRoom(partyName, options, null);
    }

void OnCreatedRoom()
    {
        PhotonNetwork.room.SetCustomProperties(new ExitGames.Client.Photon.Hashtable() {{ "pwd", partyPwd }});
    }

And elsewhere:

foreach (Room party in PhotonNetwork.GetRoomList())
        {
            ...

            string password = party.customProperties["pwd"];
            ...
         }

this last piece of code is still returning that party.customProperties[“pwd”] is an object, when it’s a string … :cry: (or at least the value is a string, i’m missing something here?)

I’m not familiar with the Photon hashtable, but it might be storing the value as an object since you never seem to declare the type. Try unboxing the result:

string password = (string)party.customProperties["pwd"];

Nope, it must comes from elsewhere:

// Script 1
void OnJoinedLobby()
    {
        options = new RoomOptions();
        options.MaxPlayers = 4;
        options.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable();
        options.CustomRoomProperties.Add("pwd", partyPwd);
        options.CustomRoomPropertiesForLobby = new string[] { "pwd" };
        PhotonNetwork.CreateRoom(partyName, options, null);
    }
    void OnCreatedRoom()
    {
        Debug.Log("Host created a Room");
        Debug.Log("WADAFUK: " + PhotonNetwork.room.customProperties["pwd"]); // The password is shown, ALL OK.
    }



// Script 2
void OnReceivedRoomListUpdate()
    {
        DrawPartiesList("");
    }

void DrawPartiesList(string search)
    {
        foreach (RoomInfo party in PhotonNetwork.GetRoomList())
        {
            GameObject listItem = Instantiate(listItemPrefab) as GameObject;
            listItem.transform.SetParent(partyListContainer.transform, false);
            string name = party.name;
            string players = party.playerCount.ToString() + "/" + party.maxPlayers;

            string password = (string)party.customProperties["pwd"];
            Debug.Log("debug: " + password); // console shows "debug: " ...
        }
    }

Did you get to resolve this? am stuck with this issue :frowning:

Hi,

check this: The Photon Forum is Closed Permanently. | Photon Engine

Basically, you must explicitly declare which properties you want to expose to the lobby, else they are only available for players in that room.

Bye,

Jean

1 Like

THANKS!!