add_properties

Adds the given properties to the entity if they are not present already

Arguments

  • properties - a table of properties literals or Property UserData to be added

Errors

  • Return an error if the properties list is empty
  • Return an error if the property does not has a valid ID
  • Return an error if the property is already present in the entity
  • Return an error if the property is not valid

Signature

---@param properties table[] @Array of properties to add
function Entity:add_properties(properties)

Example of Usage

-- bind the exposed entity UserData to a local variable
local entityAPI = alacrity.Entity

-- create a new random unique user ID
local id = alacrity.uuid.new_v4()

-- create a new Entity instance
local e = entityAPI.new({
    id = id,
    name = "Ad-Hoc Test Entity",
    description = "Ad-Hoc entity for testing",
    attributes = {},
    properties = {},
})

local ok, err = pcall(function()
    e:add_properties({
        { name = "level", value = 10 },
    })
end)

local level_property = e:get_property("level")
assert(level_property ~= nil)
assert(level_property.name == "level")
assert(level_property.value.Value == 10)