intfiction.org

The Interactive Fiction Community Forum
It is currently Sun May 26, 2013 3:11 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sun Jan 13, 2013 7:25 pm 
Offline

Joined: Sun Jan 13, 2013 5:32 pm
Posts: 18
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):

Code:
+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.
      }
   }
;


Top
 Profile Send private message  
 
PostPosted: Sun Jan 13, 2013 8:59 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 902
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.


Top
 Profile Send private message  
 
PostPosted: Wed Jan 16, 2013 11:03 am 
Offline

Joined: Sun Jan 13, 2013 5:32 pm
Posts: 18
Thanks, that's a useful tip!
But I still can't customize the messages successfully. Here's my UnlockWith function:

Code:
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:

Quote:
>unlock door
(with the bent key)
The lock mechanism is stiff and unlocks with a loud CLACK, echoing around the cells. The bent key doesn’t fit the lock.

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...


Top
 Profile Send private message  
 
PostPosted: Wed Jan 16, 2013 1:31 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 902
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. ";
         }
      }

   }
;

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.


Top
 Profile Send private message  
 
PostPosted: Fri Jan 18, 2013 12:33 pm 
Offline

Joined: Sun Jan 13, 2013 5:32 pm
Posts: 18
Jim, thanks very much. I'm just beginning to understand pseudo-globals like gIobj. This is exactly what I was looking for.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group