I have a locked chest with an iron sword and I want +1 score when the iron sword is picked up. I wrote this:
9.2. Awarding points

After taking the iron sword:
increase the score by 1;
say “Taken.”

But if you drop the sword then pick it up again, it gives you one more point and I don’t want that. Can anyone give me a fix ?

Epicurieux

This exact scenario is covered in the book:

http://inform7.com/book/WI_9_2.html

``````After taking the iron sword when the iron sword is not handled:
increase the score by 1;
say “Taken.”
``````

Does that actually work? I haven’t really used Inform 7, but I tried it with borogove.app just for fun, and I couldn’t get that rule to run at all.

My only guess is that by the time it checks that after rule, the sword has already been picked up and thus handled. Well, that or that I made some typical bone-headed beginner mistake.

This was the test program I ended up with:

``````"Swordy McSwordface"

Use scoring. Maximum score is 100;

Laboratory is a room.

An elvish sword is here.

Before taking the elvish sword when the elvish sword is not handled:
say "You're about to take the sword, and it hasn't been handled before.";
continue the action.

Before taking the elvish sword when the elvish sword is handled:
say "You're about to take the sword, and it has been handled before.";
continue the action.

After taking the elvish sword when the elvish sword is not handled:
say "You took the sword, and it hasn't been handled before.";
continue the action.

After taking the elvish sword when the elvish sword is handled:
say "You took the sword, and it has been handled before.";
continue the action.
``````

Which produced this output:

> TAKE SWORD
You’re about to take the sword, and it hasn’t been handled before.

You took the sword, and it has been handled before.

Taken.

I have already tried this. It doesn’t seem to work.

(my code)

``````The wooden chest is in Cave. The wooden chest is a container. The wooden chest contains an iron sword. The description of the iron sword is "A rusty old sword. It is a common object.". The wooden chest is fixed in place. It is opaque and closed. It is openable. It is a locked container. The old rusty key unlocks the wooden chest.
After taking the iron sword when the iron sword is not handled:
increase the score by 1;
say "Taken.".
``````

This seems to be a bug in the documentation, as described in this thread:

Either of these solutions would work, for example:

``````After taking the iron sword when the iron sword was not handled:
increase the score by 1;
say "Taken.".
``````

(Note the “`was`” instead of “`is`”.)

Or:

``````First carry out taking the iron sword:
if the noun is not handled:
increase the score by 1.
``````

(We use “`the noun`” in the rule body here to get the actual object which is concerned in the action, otherwise we might run into problems when multiple items of a kind are around, see the thread linked above.)

`For the first time`” also works well, but might cause problems in some special situations, as described in chapter 11.4 in the Recipe Book:

we should be careful not to use “for the first time” in scoring situations where it’s possible for the player to try the action but fail. Inform counts even unsuccessful attempts towards the number of times an action is understood to have occurred, so if the player tries to jump and fails, his “for the first time” will be used up and he will never receive the score points.

3 Likes

Thank you, the “was” fix worked like a charm!

Haha. Sorry for not actually testing the code before copy/pasting it from the docs!

All good