Custom lock / unlock messages on doors

I’ve been trying to get custom lock/unlock messages on a door but can’t figure out the right syntax. Basically in place of the normal “Unlocked.” when you unlock it, I wanted something like “The door unlocks with a loud click that echoes around the dungeon”. I might have other actions triggered by the noise or something (hello, time-limited escape sequence, etc).

Here’s what I have, for the door of the cell (yes, I realize it’s not usual to open a cell door from the inside):

+cellDoorInside : LockableWithKey, SenseConnector, Door 'door' 'door' "The cell door is rusted all to hell. The spacings between the bars are large, though, and you can see the corridor on the other side, and a couple of other empty cells. " connectorMaterial = coarseMesh locationList = [corridor, cell] keyList = [cellDoorKey] autoUnlockOnOpen = true dobjFor(Unlock) { action() { inherited; // here is my shady attempt to handle this - checking isLocked() after the normal inherited unlock action. // it's not very satisfactory because it just appends to any inherited message. if (!self.isLocked()) { "The unlocking of the door makes a loud CLACK noise which echoes around the dungeon. "; } } check() { // presumably i could put something in a check() or verify() function to check whether the user is // able to unlock it? but i can't get either to work. } } ;

I tested this, and quickly found the problem. You’ve put your custom message in dobjFor(Unlock). You need to put it in dobjFor(UnlockWith), as that’s the action that is invoked when the key is used to unlock the door.

Thanks, that’s a useful tip!
But I still can’t customize the messages successfully. Here’s my UnlockWith function:

dobjFor(UnlockWith) { action() { "The lock mechanism is stiff and unlocks with a loud CLACK, echoing around the cells. "; inherited; } check() { // this condition is clearly not right. if (self.getKnownKeyOwner()!=me) { reportFailure('You try to fit the key into the lock, but to no avail. '); exit; } inherited(); } }

If I drop the check function, then if I have the wrong key I get:

This is why I figure that echoing a message on a bad check is the right way to prevent this. Ideally I’d want to have the key name available so I can customize the failure message too, but one step at a time…

Okay, here’s how I would do it. I’ve included a little extra code to give the player three keys, and also included the basic cell door stuff from your original post.

[code]+ me: Actor
;

++ cellDoorKey: Key ‘cell (door) key’ ‘cell door key’
;

++ brassKey: Key ‘brass key’ ‘brass key’
;

++ rustyKey: Key ‘rusty key’ ‘rusty key’
;

  • cellDoorInside : LockableWithKey, SenseConnector, Door ‘door’ ‘door’
    "The cell door is rusted all to hell. The spacings between the bars are large, though,
    and you can see the corridor on the other side, and a couple of other empty cells. "
    connectorMaterial = coarseMesh
    locationList = [corridor, cell]
    keyList = [cellDoorKey]
    autoUnlockOnOpen = true
    dobjFor(UnlockWith) {
    check() {
    if (gIobj != cellDoorKey) failCheck (’{The iobj/he} doesn’t seem to fit the lock. ');
    }
    action() {
    inherited;
    if (!self.isLocked()) {
    "The unlocking of the door makes a loud CLACK noise which echoes around the dungeon. ";
    }
    }

    }
    ;[/code]
    The check() method checks the value of gIobj. If it’s wrong (because the wrong key is being used), the failCheck macro prints out a parameterized message that embeds the name of the current iobj.

Jim, thanks very much. I’m just beginning to understand pseudo-globals like gIobj. This is exactly what I was looking for.