expectedValues parameter in SetCustomProperties

Hi @JohnTube ,

How to use the expected values parameter setcustom properties function.

Let consider the below scenario:

We have round table setup and it has 6 player position When click the table respective player will be go to any one position. in this case we have got one issue. At the same time 2 players click the same table both we got same position.

We have checked the position is free or not by using player properties. The following code has broadcasting the free player positions:

ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable();
properties.Add( "freeposition" freePlayerPosition );

ExitGames.Client.Photon.Hashtable expectedValues = new ExitGames.Client.Photon.Hashtable();
expectedValues.Add(freeposition,freePlayerPosition);


m_Player.CustomProperties.SetCustomProperties( properties,expectedValues)

The above code does not work so please let me know how to pass the expected properties as a second parameter.

Thanks in Advance.

Comments

  • Hi @SaravanaPerumal,

    There are three different things to consider:

    1.
    m_Player.CustomProperties.SetCustomProperties( properties,expectedValues)
    
    this is wrong, it should be:
    m_Player.SetCustomProperties( properties,expectedValues);
    

    CustomProperties is of type Hashtable.
    m_Player is of type Player.

    2. This problem is better solved using ROOM properties. Where each of the 6 table spots is a property on its own OR the whole table spots is a single property. Then use PhotonNetwork.CurrentRoom.SetCustomProperties(properties, expectedValues).
    3. CAS (Check-And-Set or Compare-And-Swap, via ExpectedProperties/ExpectedValues) does not work in initialization (when the server does not have the property yet), so you need to initialize the property/properties during room creation.
  • Hi @JohnTube 6 position has a different property, which value send expected properties to avoid get same position to different players.

    I have to set each player has own position so i have to use player properties.

    Please let me know the how to use expected properties for avoid got same position.

    The following code has correct or not properties and expected values has same key value pair.

    ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable();
    properties.Add( "freeposition" freePlayerPosition );

    ExitGames.Client.Photon.Hashtable expectedValues = new ExitGames.Client.Photon.Hashtable();
    expectedValues.Add(freeposition,freePlayerPosition);


    PhotonNetwork.player.SetCustomProperties( properties,expectedValues)
  • I have to set each player has own position so i have to use player properties.

    I don't agree.
    I don't think if each player sets his own custom property without knowing positions of others would work.

    How would you initialize the player property?
    To what value would you update it? how do you get first clear position or first position not claimed?

    Your code would work to avoid trying to switch positions by same player maybe.

    I see that you are still using PUN Classic.

    Something like this.

    if you want callbacks for failure you need something like this (advanced, PUN2).
  • Ok Thanks @johntube I will try and let you know.
Sign In or Register to comment.