Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Is there a way to test for the state of a door?

I want to flip a boolean when the door state changes, but on_open/on_close/on_lock/on_unlock don't work in 8-bit mode.  I can't code it manually with 'unlock door' etc. because the match doesn't necessarily result in the door state changing.

The only workaround I can see is to code the whole thing manually with door_operation - just wondering if there's an easier way of doing things.

(1 edit)

You're right, there is currently no way to test for the state of a door., and those event handlers (on door) are not currently mapped in 8-bit mode.

I'll see what I can do at my end, but it'll probably be a week before I can look at this.

You can work around this by manually coding a door, or possibly by using the door_operation function (if it's possible).

This should get you started if you want to take this path (remove the door from the barrier section).

// Boolean section
booleans {
   is_door_locked : boolean "true";
   is_door_open   : boolean "false";
}
// In on_command{} section
: match "open door" {
   // Code your open door logic here
}
: match "close door" {
   // Code your close door logic here
}
: match "unlock door" {
   // Code your unlock door logic here
}
: match "lock door" {
     // Code your lock door logic here
}
// Direction that door is blocking
: match "n _" {
   : if (is_at "your_location_id" && is_door_open == false) {
     // This manually blocks (without using the blocks {} section
     : print "The door is in your way";
     : done;
   }
}

Thanks - I'll have a go with this.

That sounds like a question for Chris. I can't find any way of testing the state of doors. I've done lots of doors, but I always do it manually so that I'm fully in control and my doors are bidirectional. It's pretty easy. Do you want me to post some sample code? If so, is your door lockable? (It sounds like it is.)

It is lockable, yes.  I'm going to try the workaround Chris posted above, but it might be useful to have some alternatives - thanks!

My solution follows the same outline that Chris posted. Give me a moment and I'll dig one out for you.

I just did this in a text editor, so I hope I got all the brackets and indents right. It is untested.

I have assumed that the door is between room01 and room02. You go north from room01 to room02 and south from room02 to room01. The door is initially locked and closed and is unlocked using the key. The door appears in both rooms and can be opened, closed, locked and unlocked from both sides. Room and object definitions are not shown. You can optionally use a barrier if you want the exits to appear and disappear depending on whether or not the door is open.

Enjoy.

booleans {
   is_door_locked : boolean "true";
   is_door_open : boolean "false";
}
on_command {
   : if (is_present "door") {
      : match "examine door" {
         : append "It's a large door that's currently ";
         : if (is_door_open) {
            : print "open.";
            : done;
         }
         : print "closed.";
         : done;
      }
      : match "open door" {
         : if (is_door_open) {
            : print "It's already open.";
            : done;
         }
         : if (is_door_locked) {
            : print "It's locked.";
            : done;
         }
         : set_true "is_door_open";
         : print "You open the door.";
         : done;
      }
      : match "close door" {
         : if (!is_door_open) {
            : print "It's already closed.";
            : done;
         }
         : set_false "is_door_open";
         : print "You close the door.";
         : done;
      }
      : match "unlock door" {
         : if (!is_door_locked) {
            : print "It's already unlocked.";
            : done;
         }
         : if (is_carried "key") {
            : set_false "is_door_locked";
            : print "You unlock the door with the key.";
            : done;
         }
         : print "You'll need a key to unlock the door.";
         : done;
      }
      : match "lock door" {
         : if (is_door_locked) {
            : print "It's already locked.";
            : done;
         }
         : if (is_door_open) {
            : print "You'll have to close it first.";
            : done;
         }
         : if (is_carried "key") {
            : set_true "is_door_locked";
            : print "You lock the door with the key.";
            : done;
         }
         : print "You'll need a key to lock the door.";
         : done;
      }
      : match "n _" {
         : if (is_at "room01" && !is_door_open) {
            : print "You'll have to open the door first.";
            : done;
         }
      }
      : match "s _" {
         : if (is_at "room02" && !is_door_open) {
            : print "You'll have to open the door first.";
            : done;
         }
      }
   }
}
on_pre_describe {
   : if (is_just_entered() && (is_at "room01" || is_at "room02")) {
      : create "door";
   }
}

Fab!  Thanks Garry.

(1 edit)

 on_pre_describe {} doesn't work in 8-bit compatibility mode, but you won't need it if you describe the door in the location text itself or somewhere else.

You can use an "open/unlocked door" object and a "closed/locked door" object and reuse them in other parts of the game.

When a door is unlocked, I prefer it to be opened automatically as well.

I don't. I think implicit opening of a door is a really bad thing and it should be banned. Unlocking and opening are two entirely different actions and may affect puzzles. It's really no big deal for the player anyway. You just say UNLOCK DOOR. OPEN IT.

Even worse is when people expect a door to automatically be unlocked when it is opened. For example, imagine that you have to pick the lock with a paperclip in order to unlock the door. The player hasn't tweaked to that, but they happen to have the paperclip with them. They say OPEN DOOR (not even knowing that it was locked in the first place) and the door magically opens, thus solving a puzzle and the player doesn't even know that it was a puzzle or that they've just solved it.

And should the opposite be true? When you close a door, should it automatically be locked? There's no point having locked doors at all if you're going to automate everything.

(1 edit)

>Unlock door
You unlock the door with the key and open it.

You unlock the door and open it and go inside and find a grue and draw your sword and slay it and take the treasure and...

Get the idea? The game is doing things that you didn't ask it to do. You might as well just say SOLVE GAME.

Artificial intelligence applications: autonomous game.

It's time to wake up Garry! It's 2020.