# Item durability

how could i make an item have a durability, or a number of uses. i am assuming it would be something like:

durability is a value.
if value is <0 say “item breacks” remove [item] from play
if value is >0 use item

or something like that

actually i realized that when using item their should either be a chance of durabilty going down or that the durability just goes down by one.

Well, here’s a very bad way to do it.

[code]A thing has a number called durability. The durability of a thing is usually -99. [something with a durability of -99 will never break. In this example, the player is the only thing with a durability of -99.]
Definition: A thing is breakable if its durability is not -99.

Before doing something when the noun is breakable:
if the durability of the noun is less than 0:
say “[The noun] breaks!”;
remove the noun from play;
stop the action;
if a random chance of 1 in 2 succeeds:
say “[The noun] degrades a little as you use it.”;
decrement the durability of the noun; [this just means subtract 1 from it]
if the durability of the noun is less than 0:
say “[The noun] seems like it will no longer be usable.”;
if the durability of the noun is 0:
say “[The noun] seems to be on the point of breaking down.”

Before doing something when the second noun is breakable:
if the durability of the second noun is less than 0:
say “[The second noun] breaks!”;
remove the second noun from play;
stop the action;
if a random chance of 1 in 2 succeeds:
say “[The second noun] degrades a little as you use it.”;
decrement the durability of the second noun; [this just means subtract 1 from it]
if the durability of the second noun is less than 0:
say “[The second noun] seems like it will no longer be usable.”;
if the durability of the second noun is 0:
say “[The second noun] seems to be on the point of breaking down.”

Starter is a room. A table is a supporter in starter. The durability of the table is 10. A pen is in Starter. The durability of the pen is 2.

Test me with “get pen/x pen/put pen on table/get pen/drop pen”.
[/code]

A problem with this is that a breakable item may degrade whenever you do anything with it. Picking it up, putting it down, examining it, whatever. You almost certainly don’t want that. Depending on how many breakable items you have in the game, you might try writing a routine for reducing the durability of an item, and calling that routine whenever you do one of the things that might break it down:

[code]A thing has a number called durability. The durability of a thing is usually 99. [In this version, if you never call the durability check, the durability won’t matter.]

To check degradation of (item - a thing):
if the durability of the item is less than 0:
say “[The item] breaks!”;
remove the item from play;
stop the action;
if a random chance of 1 in 2 succeeds:
say “[The item] degrades a little as you use it.”;
decrement the durability of the item; [this just means subtract 1 from it]
if the durability of the item is less than 0:
say “[The item] seems like it will no longer be usable.”;
if the durability of the item is 0:
say “[The item] seems to be on the point of breaking down.”

Before putting something on the table: check degradation of the table.
Before dropping the pen: check degradation of the pen.

Starter is a room. A table is a supporter in starter. The durability of the table is 2. A pen is in Starter. The durability of the pen is 2.

Test me with “get pen/put pen on table/get pen/put pen on table/get pen/put pen on table/get pen/put pen on table/get pen/drop pen/get pen/drop pen/get pen/drop pen/get pen/drop pen”.[/code]

If there are so many breakable things that it’s not practical to write “before” rules for each of them, you might want to come up with a way to automate it; maybe by defining an adjective (you could say “A supporter can be fragile” and check degradation whenever you want to put something on a fragile thing), or using kinds of action (7.15) or stored actions (12.20) to write some more general rules.

And of course you’d want to give a special message for at least some things as they degrade or break down.