recalculate_attribute

Recalculate the value of the given attribute name.

Arguments

  • attr_name - The attribute to recalculate name as a string

Errors

  • Return an error if the attribute is not present in the entity

Signature

---@param attr_name string @Name of the attribute to recalculate
function Entity:recalculate_attribute(attr_name)

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 = {
        { name = "str", value = 10 },
    },
})

local ok, err = pcall(function()
    e:recalculate_attribute("dex")
end)

assert(not ok)

local ok, err = pcall(function()
    e:recalculate_attribute("str")
end)

assert(ok)