I was wondering if anyone can point me to a reference in any of the manuals, or give me an example, about how to create a person or an object which blocks the player from going in a certain direction, until the person or object is either attacked or destroyed with a weapon or item?
For example, a Troll which won’t let you cross a bridge unless you attack him with a sword…
Or a passageway in a cave covered with ice, which you have to hit with an ice pick to destroy it…
So far I can’t find a reference to creating guarded doorways in the manuals, and the section “Uncooperative Characters” in the Inform7 Handbook pretty much describes what I want to do, but doesn’t give an example of how to implement it? If anyone knows of a written script I could easily modify to do this without having to write it from scratch through trial and error, or can give me some guidance, I’d be very grateful. Thanks for any help in advance!
Here’s a bare-bones example that may help you work out how to handle this.
[code]The Courtyard is a room. The Palace is north of the Courtyard.
The guard dog is a male animal in the Courtyard. The description is “[if hostile]He looks mean and nasty[else]He’s busy chomping on the steak[end if].” The guard dog can be either hostile or munching. The guard dog is hostile.
The player carries a steak. Understand “meat” as the steak.
Instead of going north in the Courtyard:
if the guard dog is hostile:
say “The dog snarls at you and won’t let you through the door!”;
continue the action.
After dropping the steak:
now the guard dog is munching;
say “The dog spies the steak and starts munching on it. Looks like it will keep him busy for a while.”;
You would obviously want to add room descriptions and so forth. The point is, you can switch the state of the sentry object (in this case, from hostile to munching) in response to any action you like. Then write an Instead rule that prevents movement in a certain direction unless the sentry is in the proper state.
Also, for purposes of this game stub, I didn’t bother checking where the player dropped the steak. In a real game you would obviously need to make sure the action was being taken in the correct room.
The simplest case is just to block access when the obstacle is there and remove it when the player performs the right action.
The bridge is a room. The pasture is north of the bridge. The troll is in the bridge.
Instead of going north from the bridge when the troll is in the bridge:
say “‘You shall not pass,’ the troll says.”
Instead of attacking the troll:
say “You slay the troll.”;
remove the troll from play.
As is true with most things, there are lots of ways of solving a problem like this.
Here’s another option. It creates a subclass of person (called “door guard”). This could be done for things as well (so “ice” could guard a door instead), but I just made the one for ease of example:
A door guard is a kind of person. A door guard has a door called the guarded door. A door guard can be guarding. A door guard is usually guarding.
Check going through a door (called target) when a door guard is in the location:
repeat with guard running through guarding door guards in the location:
if the guarded door of the guard is the target:
say "[The guard] steps in front of you and blocks you from using [the target]." instead.
The Throne Room is a room. East of the throne room is a door called the king's door. East of the king's door is the King's Bedchamber.
The armed guard is a door guard. The guarded door of the armed guard is the king's door. The armed guard is in the throne room.
[Create some way to get the guard to stop guarding]
Instead of singing when the location is the throne room:
say "The guard starts laughing and is distracted.";
now the armed guard is not guarding.
Thanks a lot, I’m going to work with all these examples I’m sure they’ll come in useful! It’s beginning to feel like creating and writing IF is just about as challenging and rewarding as an experience as playing an IF game, complete with its own puzzles and obstacles and mysteries to solve and get past along the way. Thanks again.
There are more than a few people (myself included) who find that writing IF is actually more fun than playing it.
I’ve got these examples working so thanks, but one more thing for anyone who cares to answer, what if I want to have the player use a weapon to attack the guard with? And if the player doesn’t have a certain weapon, the action fails?
Such as USE/ATTACK/STAB/HIT TROLL with SWORD/CLUB/ECT.?
Trying to get I7 to understand “Instead of attacking the troll with the sword” doesn’t compile?
You need to create a new action as the standard library has only the attacking action with just one noun. Creating new actions is covered in the manual from chapter 12.7 onward and example “Lanista 2” in chapter 16.3. has an example of creating an attacking it with action.