# Armor Decreasing the amount of Damage Inflicted

I’ve read the documentation about armor, I’ve looked at the " The Reliques of Tolti-Aph" example by Graham Nelson. I’ve looked at some of the conversations here, and I cannot for the life of me figure out how to get the armor working. I want the armor being worn to decrease the amount of damage a person receives (the player and anyone else in the game that is defined as a person). I have the combat mechanics working just fine EXCEPT for the armor part. So it’s just the armor addition that I need help with. The bolded part is what I can’t figure out.

Here is what I have:

``````The attacking it with action has a number called the damage inflicted.

**A protection is a kind of thing. A protection is wearable. A protection has a number called maximum resistance.**

**Carry out calculating maximum damage of a person (called the actor):**
**	if the actor is wearing protection and the damage inflicted is greater than 1:**
**		say ": [the protection] absorbs ";**
**		let the absorbency be the maximum resistance of the protection;**
**		if the absorbency >= the damage inflicted:**
**			let the absorbency be the damage inflicted;**
**			decrease the absorbency by 1;**
**		decrease the damage inflicted by the absorbency;**
**		say the absorbency;**
**	continue the activity.**
``````

I forgot to mention: I ONLY want the armor to work if the person is WEARING the armor - not just holding it (this includes shields).

You may be getting tripped up by the fact that by making damage inflicted a variable of the attacking it with action, it won’t be available to the calculating maximum damage of a person activity. And an activity may be overcomplicated here: a `To decide what number is...` phrase may suffice.

You can loop through protections worn by someone with those very words:

``````repeat with item running through protections worn by the actor
``````

I’m sorry, but I don’t understand what you mean, exactly (still pretty new to Inform).

There are several problems in your code snippet. It does not look like it will compile as presented.

Because you are specifying a `carry out` rule, it appears that you have tried to create an action called `calculating maximum damage of`. Is that the case?

If not, then you’re missing some important things about how rules work. I would suggest reviewing WWI 19.1 On rules, WWI 19.7 The preamble of a rule and WWI 12.2 How actions are processed as starting points. Important: The `continue the activity` statement may not have the effect that you think it does. Activities are different from actions – see WWI 18.1 What are activities? I believe that Zed thought you were creating an activity because your rule ends with that phrase, but my guess is that you meant `continue the action` (which is superfluous at the end of a `carry out` rule, actually).

If you are creating a `calculating the maximum damage of` action, then I agree with Zed that you’re probably overcomplicating things and would be better off with a phrase to decide – see WWI 11.17 Phrases to decide other things. As Zed notes, the `actor` variable is normally only available within action processing rules, which can complicate matters. You can get around this by creating phrases with parameters, as in:

``````To decide which number is the maximum damage of (victim - a person):
... [code here can reference the "victim" parameter]
``````

Then, in other code, you can use the phrase (like calling a function) in your action processing rules via:

``````let max damage be the maximum damage of the actor;
``````

or just use the result as the parameter of another phrase, as in:

``````decrease hit points of the actor by the maximum damage of the actor;
``````

Also, the way that you reference “`the protection`” isn’t allowed. The compiler will understand `protection` to mean the name of a kind, per your declaration. Multiple protections might exist, and, by default, multiple protections could be worn by any one person, so there is no single one that can be presumed to be “the” singular one at compile time. Zed’s reply is pointing out how to cycle through the various protections that might be worn at once.

1 Like