How To Synchronize A Numeric Room Property As A New Member

Here, we explain how to synchronize room properties using an example.

When a new member joins the room, the new member client needs to retrieve the current value of the numeric room property.

// We retrieve "HP" as we join a room
room.OnJoin += OnDiarkisRoomJoin;

private void OnDiarkisRoomJoin(bool success, uint createdTime)
{
        if (!success)
        {
                // Handle error...
                return;
        }

        // Retrieve "HP"
        List<string> propertyNames = new List<string>();
        propertyNames.Add("HP");
        // This raises OnGetProperties event and that is how you retrieve the property data
        room.GetProperties(room.GetRoomID(), propertyNames);
}

// This is how to retrieve "HP" from the server
room.OnGetProperties += OnDiarkisRoomGetProperties;

private void OnDiarkisRoomGetProperties(bool success, Dictionary<string, byte[]>properties)
{
        if (!success)
        {
                // Handle error...
                return;
        }

        if (!properties.ContaionsKey("HP"))
        {
                // "HP" is missing...
                return;
        }

        // Update local "HP"
        Array.Reverse(properties["HP"]); // Big Endian
        _hp = BitConverter.ToInt64(msg.Value, 0);
}