How do I say something after killing a guard?

I already have the combat part worked out, but I don’t know of any “when” commands other that every turn.

Every turn: if the guard is dead, say "A good blow to the head finishes off the guard. He has a black keycard on his belt." 

I have everything working, but I don’t know how to make it not repeat “A good blow to the head etc.” every turn. Please help!

Consider putting this code in the same place that you check for hp decreasing to 0.

I might do something like :

To finish is a verb.
A person has a text called the death text. The death text of a person is usually "[We] [finish] off [the item described]."

and then, later:

	if the health of the enemy is less than 1:
		now the enemy is dead;
		say "[death text of the enemy][line break]";

I’m getting: The text ‘The death text of a person is usually “[We] [finish] off [the item described].” if the health of the enemy is less than 1, now the enemy is dead’ is followed by a semicolon ‘;’, which only makes sense to me inside a rule or phrase (where there’s a heading, then a colon, then a list of instructions divided by semicolons). Perhaps you want a full stop ‘.’ instead?

You can’t just cut and paste the second block of code that I posted. You need to find the part of your program where you check to see if the player has killed his opponent and, if so, add a line that prints the opponent’s death text, using the posted code as an example.

Couldn’t you do it with a number variable?

[code]Guard-dead is a number variable. Guard-dead is 0.

Every turn: if guard-dead is 0:
change guard-dead to 1;
if the guard is dead, say “A good blow to the head finishes off the guard. He has a black keycard on his belt.” [/code]

There’s probably a much more elegant way to do it than that but it (should) work (in theory).

If you want to use a variable to keep track of whether you’ve printed the message, it doesn’t have to be a number; you could just use a truth state.

[code]Guard obituary printed is a truth state variable. Guard obituary printed is false.

Every turn when the guard is dead and guard obituary printed is false:
say “A good blow to the head finishes off the guard. He has a black keycard on his belt.”;
now guard obituary printed is true.[/code]

More importantly, you want to make sure to put your conditions in the right order; the way you have it written, on the first turn your rule will run and change guard-dead to 1, and the message won’t print because the guard isn’t dead. Then when the guard does die the message won’t print, because guard-dead has been changed to 1. (Also, as a heads-up, in recent versions of Inform you can’t say “change guard-dead to 1”; it has to be “now guard-dead is 1.”)

In any case, I think Vince is right that the best place to print this message is at the point in the combat code where it checks whether you’ve just killed the guard, since the text describes the action you’re taking. Otherwise it’s very easy to wind up with messages printing in a weird order; for instance, if you have other Every Turn rules printing messages, you might wind up with something like this:

when the last line would go better with the message about hitting the guard.

Ah, good point. It looked okay when I typed it there but I hadn’t actually tested it. (Hence the in theory in brackets.) I’m still using an older version of Inform so I still think in terms of “change guard-dead to 1” rather than “now guard-dead is 1.”

I also think it is better not to use an Every turn rule, but if you use one, you can get rid of the boolean by using the past tense:

Every turn when the guard was not dead and the guard is dead: say "A good blow to the head finishes off the guard. He has a black keycard on his belt."I haven’t tested it and I’m not 100% sure it works as expected because I dont use past tenses often.

The “was not dead” part means that the guard wasn’t dead at the begining of the action, so the rule will only fire once, when the guard was alive at the start of the turn but dead now. See section “The past and perfect tense” in the “Time” chapter.

I guess this approach is better if there are multiple guards, so you don’t create a variable for each.