Knock out someone

The character I have created, is required to get past a guard. As per the rules created he is not allowed to kill the person. So my plan was to make him knock out the guard. I am not able to do this. Does anyone have any suggestions ?

I have a general suggestion: Break the problem down into little, manageable chunks, and tackle them separately.

First you need to create a “knock out” action. This will have to understand both “knock out guard” and “knock guard out”, as these are both valid English word orders.

Second, the guard will have to become inert when he’s knocked out. One standard way of doing this is by whisking the guard object offstage and replacing it with an unconscious guard object.

Third, you need to set up the travel restrictions so that the guard prevents the travel, but the unconscious guard doesn’t.

Fourth, make sure that the game understands “hit guard” as a synonym for “knock out guard”, or at least gives a more appropriate reply than the default “Violence is not the answer to this one.”

Also, an alternative to the object swapping trick is to just give the guard (or even all people, if your character is going to be knocking lots of people out) a consciousness attribute and testing it:

The Vault is north of the Vault Entrance. The guard is a man in the entrance. "[A guard] [if conscious]stands here, blocking your way[else]lies unconscious on the ground[end if]." The description is "He's [if conscious]here to keep unauthorized people out of the vault[else]going to be really pissed off when he wakes up[end if]." The guard can be unconscious or conscious. The guard is conscious.

Instead of going from the entrance to the vault when a conscious guard is in the location, say "[The guard] blocks your way."

Actually, I was a bit bored, so I decided to practice my Inform skills and flesh that out into a complete working example:

"The Thief and the Guardian" by Vyznev Xnebara

The Entrance is a room. "You stand before a gate leading north into the high security vault." The printed name is "Vault Entrance". The Vault is north of the Entrance.

The uniformed guard is a man in the entrance. "[A guard] [if conscious]stands in a rigid posture by the vault entrance, blocking your way[else]lies unconscious on the ground next to the vault entrance[end if]." The description is "He's [if conscious]here to keep unauthorized people out of the vault[else]going to be really pissed off when he wakes up[end if]." The guard can be unconscious or conscious. The guard is conscious. Understand "guardian" as the guard.

Instead of going from the entrance to the vault when a conscious guard is in the location, say "[The guard] blocks your way."

A sign is fixed in place in the entrance. "A sign is mounted on the wall next to the guard post, forbidding entry." The description is "It reads 'AUTHORIZED PERSONNEL ONLY'."

The player carries a blackjack. The description of the blackjack is "A short baton with a lead weight wrapped in leather on the end, designed for knocking people unconscious. Getting hit with it would be painful, but probably not lethal. Probably." Understand "black", "jack", "baton" and "cosh" as the blackjack.

Understand "knock out [a person]" as attacking. Understand "knock [a person] out/unconscious" as attacking. 

Understand the command "kill" as something new. Understand "kill [a person]" as a mistake ("You have sworn not to do that.")

Instead of attacking the conscious guard when the player has a blackjack:
	say "Feigning casual interest in the sign, you surreptiously position yourself next to [the guard], where he can only see you in peripheral vision. As you sense his eyes briefly straying elsewhere, you quickly raise your blackjack up behind his back and, with a smooth and practiced movement, bring it down on the back of his head. [paragraph break]";
	now the guard is unconscious;
	increment the score;
	say "The guard falls down, unconscious. Fortunately, he doesn't seem to have suffered any permanent damage, though with head injuries it's hard to be sure."	

Instead of attacking the unconscious guard, say "He's already unconscious."

Instead of attacking the guard, say "You'd feel a lot more confident about your chances of knocking out [the guard] if you had your blackjack."

After going to the vault:
	say "Congratulations, you've made your way into the high security vault. Now get what you came for and leave before the guard wakes up and sounds the alarm.";
	end the story finally.
	
The maximum score is one.

Test me with "x guard / x sign / n / drop blackjack / hit guard / kill guard / get all / x blackjack / knock guard unconscious / l / x guard / hit guard / n".

thank you. The code worked

It is generally much better to use a carry out going rule rather than an after going rule. After going rules are especially bad as they prevent the room description from being shown.

Well, that particular rule also ends the story, but still, a good point. Thanks.

However, “carry out going” rules have their own problems; it’s not always obvious whether they fire before or after the actual movement. For example, consider this simple example:

The Kitchen is a room. "A small but cozy kitchen, with everything you need at hand."

The Dining Room is north of the kitchen. "The dining room is hardly lavish, but it does have a certain domestic elegance."

Carry out going: say "Here you are in [the location]."

So far this works fine, but what if we only want this to happen for some rooms? OK, easy enough:

The House is a region. The kitchen and the dining room are in the house.

Carry out going to the house: say "Here you are in [the location]."

Oopsie! If you try that out, you’ll see something like this:

Kitchen
A small but cozy kitchen, with everything you need at hand.

>n
Here you are in the Kitchen.

Dining Room
The dining room is hardly lavish, but it does have a certain domestic elegance.

>s
Here you are in the Dining Room.

Kitchen
A small but cozy kitchen, with everything you need at hand.

>

That’s because the extra condition on the rule made it more specific than the standard “carry out going” rules, and it therefore fires before them.

OK, sure, you can work around this in various ways, for example like this:

Carry out going to a room (called the destination) in the house:
	say "Here you are in [the destination]."

but that could still bite you if you try to interact with the player’s surroundings in any way, since even though the message says you’re at the destination, actually you’re not yet there.

The cleanest solution, to me at least, would seem to be simply this:

After going to the house: say "Here you are in [the location]."; continue the action.

…although I suppose this could also be argued for:

Last carry out going to the house: say "Here you are in [the location]."

You just need to make sure you rule fires after the move player and vehicle rule. So something like this.

Carry out going: if the player is in the house, say "Here you are in [the location].".

It’s now very easy to add extra “if” conditionals for other cases.