Alternative for Lists in the roomprops

Options
Hi,

When a trigger gets fired I want to add a string to a List saved in the roomprops. Then this list will be passed in
OnPhotonCustomRoomPropertiesChanged().
But Lists can't be used in the roomprops,
see error : Exception: cannot serialize(): System.Collections.Generic.List`1[System.String].
And an array won't work, there you can't add an element to an array.
Does somebody knows a workaround?
Best regards,
Nikola

Comments

  • Nikolasio
    Options
    So I tried the following with an array:
    public override void OnCreatedRoom() { Hashtable roomProps = new Hashtable(); roomProps.Add(RoomExtensions.spawnPositions, new Vector3[RoomExtensions.spawnPositionsArrayLength]); roomProps.Add(RoomExtensions.winTime, new float()); <b class="Bold">roomProps.Add (RoomExtensions.winnerName, new string[RoomExtensions.initialPlayersLength]);</b> PhotonNetwork.LoadLevel(onlineSceneIndex); }

    The following error occurs when the key pair 'RoomExtensions.winnerName, new string[RoomExtensions.initialPlayersLength] ' is added: "MissingReferenceException: The object of type 'UIMain' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object."

    I added this method to the room extensions:
    public static void AddWinnerName(this Room room, string winName) { string[] names = room.GetWinnerNameArray (); if (names[0] != null) { names[1] = winName; } else { names[0] = winName; } room.SetCustomProperties(new Hashtable() {{winnerName, names}}); }

    The error only occurs when I add the key pair 'RoomExtensions.winnerName, new string[RoomExtensions.initialPlayersLength] '. I fail to see why.

    Any thoughts anybody?

    Best regards,
    Nikola
  • Nikolasio
    Nikolasio
    edited July 2017
    Options
    check
  • Nikolasio
    Options
    Ok then, having trouble displaying the code correctly.
    So I tried to add an array to the roomprops. I want to save the winner's name and incase of an ex aequo both names, hence the array of length 2.
    public override void OnCreatedRoom() { Hashtable roomProps = new Hashtable(); roomProps.Add(RoomExtensions.spawnPositions, new Vector3[RoomExtensions.spawnPositionsArrayLength]); roomProps.Add(RoomExtensions.winTime, new float()); roomProps.Add (RoomExtensions.winnerName, new string[RoomExtensions.initialPlayersLength]); PhotonNetwork.room.SetCustomProperties(roomProps); //load the online scene PhotonNetwork.LoadLevel(onlineSceneIndex); }

    Before adding the key pair 'RoomExtensions.winnerName, new string[RoomExtensions.initialPlayersLength]' everything worked fine and the online scene got loaded.
    After adding the new key pair, not any more and the following error occurs: "MissingReferenceException: The object of type 'UIMain' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object."

    In my roomextensions class I added these 2 methods:
    public static string[] GetWinnerNameArray(this Room room) { return (string[])room.CustomProperties[winnerName]; } public static void AddWinnerName(this Room room, string winName) { string[] names = room.GetWinnerNameArray (); if (names[0] != null) { names[1] = winName; } else { names[0] = winName; } room.SetCustomProperties(new Hashtable() {{winnerName, names}}); }

    I fail to see why the error occurs.

    Any thoughts anyone?

    Best regards,
    Nikola




  • Hi @Nikolasio,

    when you create the Room Properties you only add empty arrays to it as far as I see. For example roomProps.Add (RoomExtensions.winnerName, new string[RoomExtensions.initialPlayersLength]); adds an empty array (array of null values) with the length of initialPlayersLength, but it doesn't set any kind of data. The same applies to the other Room Properties as well.
  • Nikolasio
    Nikolasio
    edited July 2017
    Options
    Hi @Christian_Simon,

    Yes idd, on room creation I set the initial room properties. And then use get and set var/methods in my roomextensions for the customproperties.
    It worked fine for the spawn positions and the winTime but not for the winnerName array.
    So maybe the problem lies in my get and set methods?

    Btw any tips on displaying the code correctly. Now I copy paste the code between "code class="CodeInline" and "/code", but it doesn't display nicely.

    Cheers,
    Nikola
  • It seems that you can't use string-arrays in the Custom Room Properties. At least my tests failed when using string-arrays and the client got disconnected. Can you please check if your client gets disconnected as well when trying to call SetCustomProperties with the created hashtable containing at least one string-array?
  • Nikolasio
    Options
    yes exactly the same here, disconnecting from my online scene.

    So no Lists and string Arrays in the Custom Properties then.

    I will try the custom player properties, I think that could be a workaround for me.
  • Nikolasio
    Options
    To summarize:
    - Lists and string Arrays are not possible in the Custom Properties
    -But string, int, float is possible

    I got my need for a List out the custom properties and worked with RPC's.