remove_properties

Removes the given properties from the entity if they are present. This function does not return errors if the properties are not present in the entity.

Arguments

  • properties - A table of Property instances, property Lua tables or property names to be removed.

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 = {
        { name = "level", value = 10, hide_from_conditions = false },
        { name = "mental_condition", value = "bad", hide_from_conditions = false },
        { name = "origin", value = "earth", hide_from_conditions = false },
        { name = "last_room", value = 1000, hide_from_conditions = true },        
    }
})

local ok, err = pcall(function()
    e:remove_properties({
        "level",
    })
end)
assert(ok and err == nil)

-- check that the level property is not present in the entity anymore
local ok, err = pcall(function() 
    e:get_property("level")
end)
assert(not ok and string.find(tostring(err), "property 'level' not found in entity"))

local ok, err = pcall(function()
    e:remove_properties({
        { name = "origin", value = "" },            -- use Lua table value 
        alacrity.Property.new("last_room", ""),     -- use Property instance
        "mental_condition",                         -- Use just a string with the property name
    })
end)
assert(ok and err == nil)

-- check that the properties table in the entity is empty
if next(e.properties) ~= nil then
    error("entity.properties is not empty")
end