Tags¶
> tag obj = tagname
obj.tags.add("mytag", category="foo")
obj.tags.get("mytag", category="foo")
from evennia import DefaultObject
from evennia import TagProperty, TagCategoryProperty
class Sword(DefaultObject):
# name of property is the tagkey, category as argument
can_be_wielded = TagProperty(category='combat')
has_sharp_edge = TagProperty(category='combat')
# name of property is the category, tag-keys are arguments
damage_type = TagCategoryProperty("piercing", "slashing")
crafting_element = TagCategoryProperty("blade", "hilt", "pommel")
In-game, tags are controlled tag
command:
> tag Chair = furniture
> tag Chair = furniture
> tag Table = furniture
> tag/search furniture
Chair, Sofa, Table
Tags are short text lables one can ‘hang’ on objects in order to organize, group and quickly find out their properties. An Evennia entity can be tagged by any number of tags. They are more efficient than Attributes since on the database-side, Tags are shared between all objects with that particular tag. A tag does not carry a value in itself; it either sits on the entity
You manage Tags using the TagHandler
(.tags
) on typeclassed entities. You can also assign Tags on the class level through the TagProperty
(one tag, one category per line) or the TagCategoryProperty
(one category, multiple tags per line). Both of these use the TagHandler
under the hood, they are just convenient ways to add tags already when you define your class.
Above, the tags inform us that the Sword
is both sharp and can be wielded. If that’s all they do, they could just be a normal Python flag. When tags become important is if there are a lot of objects with different combinations of tags. Maybe you have a magical spell that dulls all sharp-edged objects in the castle - whether sword, dagger, spear or kitchen knife! You can then just grab all objects with the has_sharp_edge
tag.
Another example would be a weather script affecting all rooms tagged as outdoors
or finding all characters tagged with belongs_to_fighter_guild
.
In Evennia, Tags are technically also used to implement Aliases
(alternative names for objects) and Permissions
(simple strings for Locks to check for).
Aliases and Permissions¶
Aliases and Permissions are implemented using normal TagHandlers that simply save Tags with a
different tagtype
. These handlers are named aliases
and permissions
on all Objects. They are
used in the same way as Tags above:
boy.aliases.add("rascal")
boy.permissions.add("Builders")
boy.permissions.remove("Builders")
all_aliases = boy.aliases.all()
and so on. Similarly to how tag
works in-game, there is also the perm
command for assigning permissions and @alias
command for aliases.