How does one code an NPC that must be defeated to progress?

I’m new to Inform (specifically and I have a coding question. I can’t find a way to make it so the player is unable to leave the room they are in until they kill a non-player entity. And the phrase: end game in victory does not seem to work. :frowning: Could someone help me please.

There are a lot of different ways to do this. One way is to use a check rule to see if the NPC exists.

Before going when the location is Roman Arena:
     if the location of Gladiator is Roman Arena:
          say "The Gladiator prevents you from escaping!" instead.[/code]

This then hinges on removing the Gladiator from play when conditions are met:

[code]After attacking Gladiator:
     say "You stab the Gladiator. 'Oof! My spleen!' he hollers, disappearing in a puff of green smoke.";
     now Gladiator is off-stage.

“Off-stage” is a special location where things go before they are put into a location, and moving something there prevents the player from encountering it.

There are other methods of doing this, but this is a simple one.

NOTE: The “attacking” action is blocked by default. You can allow it conditionally with the line:

The block attacking rule does nothing when the noun is the Gladiator.

“end the game in victory” no longer works; this post explains why this was changed. You want some variant of “end the story”, e.g.:After going to the Deadly Dungeon: end the story finally saying "You have won".(See §9.4 in the manual.)

Following the ‘removing the Gladiator from play’ option: an alternative can be to say something like:

The Gladiator can be alive or dead. The Gladiator is alive. After attacking the Gladiator: say "You stab the gladiator in the gut. He bellows in agony, then falls back, dead."; now the Gladiator is dead.

Then any checks regarding whether or not the Gladiator has been defeated can hinge on whether or not the Gladiator is dead. However, I wouldn’t recommend this unless you plan on implementing death and dying and combat regularly throughout the game.

If it’s just one puzzle, you’re likely better off using the remove-from-play method suggested above, and then adding a corpse as a separate object if needed, moving it to the location immediately after the Gladiator dies.

I block the character in various ways in “Getting To Work And Other Bullshit.” I pretty much use an if inside of a “Instead of going when is visible” type of thing.

Here’s the crawling skeleton section of my game. You have to give him cigarettes, then he “is smoking” and you can then go west.

Part 3 - The Crawling Skeleton

sidewalk_4 is north of sidewalk_3. It is traffic_west. It is in the Outdoors Area.
		The printed name is "The sidewalk".
	The description is "[one of]If there were any more crack in this sidewalk, it'd be above the belt of a plumber![or]It's a shame that there aren't more dirt paths to walk along.[cycling] 
	There's a crosswalk to the west.".
	The Crawling Skeleton is here. It is a person. It is not smoking. "Whoah! An animated skeleton is slowly, so, so, so slowly crawling towards you. It's front teeth are stained a bright yellow, but the rest is sun-bleached white.". The description is "A very slowly crawling skeleton. It seems to be trying to say something, but coughs every time.[paragraph break][italic type]Wait. Coughs? Lungs much?[roman type]".
	Instead of giving cigarette butts to Crawling Skeleton:
		move cigarette butts to skeleton;
		now Crawling Skeleton is smoking;
		say "The Skeleton stops crawling and reaches out a bony hand to snatch away the cigarette butts. It leans its frail looking body against the eastern fence and starts puffing away. The cigarette is lit and smoke is curling into his rib cage, but you know there are no lungs and he doesn't seem to have a lighter, so you can't imagine how what you're seeing is actually working...[paragraph break]'Thanks, brother, I needed this,' he says, looking at you with his empty eye sockets.[paragraph break]You tell him it's no problem and hope this is the last of the weirdness you run into on your way to work.";
		now the description of the Crawling Skeleton is "The Skeleton is propped up against the eastern fence, puffing on a cigarette butt. You still can't figure out how it does that without lungs.";
	Instead of going west when the Crawling Skeleton is visible:
		if Crawling Skeleton is not smoking begin;
			say "You try to step over the skeleton, but its bony hand snatches your ankle and he tosses you back a few steps.";
			say "The Skeleton is propped up against a fence, somehow smoking a cigarette butt. You're not sure how, without lungs and without a lighter anywhere in sight, but you shrug and go on your way trying not to think too hard about it.
			The Skeleton says, 'Thanks for the smokes, brother. I needed this to stop the morning cough.'";
			continue the action;
		end if;