Lua Tables
To create an entity programmatically using the Lua API, you might follow these steps:
Step One
Acquire an instance of the entity module:
local entity = alacrity.Entity
Step Two
Create a new minimal entity instance using the new method:
local warrior_001 = entity.new({
id = alacrity.uuid.new_v4(),
name = "Warrior Character",
description = "Ad-Hoc instance of a Warrior Human Playable Character",
attributes = {
{ name = "max_hit_point", value = 16 },
{ name = "str", value = 8 },
{ name = "dex", value = 2 },
{ name = "con", value = 6 },
{ name = "int", value = 1 },
{ name = "wis", value = 1 },
{ name = "cha", value = 3 },
-- add more attributes as needed
},
-- we could add anything else that we needed using our familiar Lua tables syntax
version = "0.0.1",
})
Step Three
Make any optional modifications
warrior_001:add_tags({
{ name = "humanoid", value = "human "},
{ name = "playable_character", value = 1 },
})
warrior_001:add_properties({
{ name = "mental_condition", value = "good" },
{ name = "level", value = 1 },
{ name = "class", value = "cleric" },
{ name = "ftue_completed", value = false, hide_from_conditions = true },
{ name = "current_tracking_quest", value = 0, hide_from_conditions = true },
{ name = "last_check_point", value = "none", hide_from_conditions = true },
-- add more properties as needed
})
💡 Tip
Remember that attributes can not be added to entity instances after they have been created already. You must make sure your entity contains all the attributes that it needs for its specific version on instantiation / definition.