TinyMUX

Lock Types and Key Expressions

Building

Lock Types and Key Expressions

Locks are boolean expressions that control who can interact with an object and how. Every lock evaluates to either true (pass) or false (fail) for a given actor. Locks are one of the most powerful building tools in MUSH.

Setting Locks

@lock thing = me                    -- Only I can pick it up
@lock/enter room = flag^wizard      -- Only wizards can enter
@lock/use button = +key_card        -- Must carry key_card

The general form is @lock[/type] object = key-expression. Without a type, the default lock is set.

Lock Types

Each lock type controls a different kind of interaction:

Lock TypeControls
defaultTaking objects, going through exits, using the use command
/enterEntering an object or room (via teleport or enter command)
/leaveLeaving an object
/useUsing an object (the use command)
/dropDropping an object
/giveGiving an object to someone
/receiveReceiving an object from someone
/pagePaging the object’s owner
/teleportTeleporting to a location
/mailSending @mail to the object’s owner
/speechSpeaking in a room (controls who can talk)
/commandUsing $-commands on an object
/parentSetting this object as a parent
/linkLinking an exit to this location
/controlControlling this object (beyond normal ownership)
/zoneZone-based control
/destroyDestroying this object
/chownChanging ownership of this object

Key Expression Grammar

Lock keys are boolean expressions built from these primitives:

Object Reference

A bare object name or dbref. Passes if the actor is that object.

@lock door = #1234            -- Only object #1234 passes
@lock door = Bob              -- Only the player named Bob passes

Identity Test (=)

Passes if the actor is exactly the specified object. Similar to a bare reference but syntactically explicit.

@lock door = =me

Carry Test (+)

Passes if the actor is carrying the specified object.

@lock door = +gold_key        -- Must have gold_key in inventory

Owner Test ($)

Passes if the actor is owned by the same player as the specified object.

@lock zone_obj = $admin_char  -- Must be owned by admin_char's owner

Indirect Lock (@)

Evaluates another object’s lock instead.

@lock exit = @master_lock     -- Use master_lock's default lock

Attribute Lock (:)

Tests an attribute value on the actor.

@lock door = faction:rebel        -- Actor's FACTION attr must equal "rebel"
@lock door = class:warrior|mage   -- Must be "warrior" or "mage"

Evaluation Lock (/)

Like an attribute lock, but the value is evaluated as softcode. The result must match.

@lock door = level/[gte(%0,10)]   -- Actor's LEVEL attr must be >= 10

Here, %0 is replaced with the actor’s value of the attribute being tested.

Boolean Constants

@lock obj = #true             -- Always passes
@lock obj = #false            -- Always fails

Combining Keys

Keys can be combined with boolean operators:

OperatorMeaning
&AND—both sides must pass
|OR—either side must pass
!NOT—inverts the result

Parentheses group expressions:

@lock vault = (+master_key & faction:guild) | =Treasurer

This lock passes if the actor carries master_key AND has faction “guild”, OR if the actor is the Treasurer.

Lock Nesting

Locks can reference other locks via indirection (@), and lock evaluation can trigger further lock checks. To prevent infinite loops, the server enforces a lock nesting limit. If exceeded, the lock fails.

Unlocking

@unlock[/type] object removes a lock, which means the lock is always considered passed (open).

Related Topics: Locks, @lock, @unlock, Control.