Skip to content

7. Scripts and Timers

A script is code with no physical presence in the game — it doesn't live in a room — that can run once, or repeatedly on a timer. It's how you make things happen on their own, without a player typing a command.

Open mudgame/typeclasses/scripts.py — the blueprint is as empty as rooms.py was:

from evennia.scripts.scripts import DefaultScript


class Script(DefaultScript):
    pass

A script that fires on an interval overrides at_repeat():

class FlickerLight(DefaultScript):
    def at_script_creation(self):
        self.key = "flicker_light"
        self.interval = 10  # seconds between ticks
        self.persistent = True

    def at_repeat(self):
        self.obj.msg_contents("The torchlight flickers.")

Attach it to a room with @py:

> @py evennia.create_script("typeclasses.scripts.FlickerLight", obj=here)

self.obj is whatever object the script is attached to — here, the room itself, so self.obj.msg_contents(...) sends the message straight to everyone standing in it.

Try it

Create a script attached to one of your rooms that prints a message every 10-30 seconds, and watch it fire while you stay in that room.

Tip

interval is in seconds, and persistent = True means the script survives a @reload — without it, reloading would stop the timer.

Next: Final Project →