Skip to content

6. Attributes

An attribute is a value stored permanently on a specific object — the Evennia version of a variable from Unit 1, except it's saved to the database instead of disappearing when the game restarts.

From the command line, @set reads and writes attributes on anything you can see:

> @set here/is_locked = True
> @set here/is_locked
here/is_locked = True

From Python — inside a command's func(), for example — you use .db:

class CmdWave(BaseCommand):
    key = "wave"
    locks = "cmd:all()"

    def func(self):
        caller = self.caller
        caller.db.wave_count = (caller.db.wave_count or 0) + 1
        caller.location.msg_contents(f"{caller.name} waves ({caller.db.wave_count} times today).")

caller.db.wave_count or 0 handles the very first wave, when the attribute doesn't exist yet — without the or 0, that line would crash with an error the first time it ran, the same kind of bug you learned to read in Unit 3, Lesson 7.

Try it

Update your wave command from Lesson 4 to count how many times each character has waved, using .db as shown above.

Tip

Anything you store with .db survives a @reload — it's only cleared if the object itself is deleted.

Next: Scripts and Timers →