Code problem

I am new and still learning IF Inform 7. What I want to do is create a container that can only hold a number of specified items and nothing else. I am bit frustrated having difficulty implementing something that should be quite simple.

The container is called a wallet. The player should be able to deposit a student card, a fifty dollar bill and a rental card in the wallet without difficulty. If the player tries to place the fire extinguisher or chair into the wallet then the action should be stopped and a message provided to support this fact. The following is a sample of code that illustrates the problem.

I also tried substituting the three “Instead of inserting something” lines with the following:

None of them worked. The player was unable to put the items “student card or fifty dollar bill or rental card” into the wallet.

The problem here is that these rules overlap so that nothing is allowed to be inserted: If you try to insert the student card, the first rule passes but because it’s not a bill or a rental card, the two other rules stop it from being inserted and so on.

This should work better, but you have to write the different parts of the condition in full and use “something” instead of “a noun” on the first line:

Before inserting something into the wallet: if the noun is not a fifty dollar bill and the noun is not a student card and the noun is not a rental card, say "You cannot put [a noun] into your wallet!" instead.

(note also “and” instead of “or”.)

Thanks a lot Juhana for your help! :stuck_out_tongue:

I should have seen that.

As you, I’m also learning I7, but I had a similar issue recently, and I think you have a better solution by giving objects a number and allow the wallet to only accept items with that number. That makes it easier for you to decide, in the future, if a created thing can be putted in the wallet or not, without having to find the line of code and add the thing’s name to that line.

It would work somehow like this (although I can’t test it now, for I’m not in a computer with I7):

[code]Things have a number called walletable. The walletable is usually 0.

Before inserting something into the wallet:
if the walletable of the noun is not 1, say “You can’t put [a noun] in the wallet.” instead.

The student card is in the example room. The wallatable is 1. The description is “The stundet card reminded you of days past. The long hair, the parties that stole study time… oh, those were the days.”

There’s no need to make this a number. You can do something like this (untested code):

[code]A thing can be walletable or nonwalletable. A thing is usually nonwalletable.

Before inserting a nonwalletable thing into the wallet . . .

The student card is a walletable thing in the example room.[/code]

Yupe, that seems even better!

Just a remark: In this case, couldn’t “Before…” be an “Instead…”? Since you wrote “nonwalletable object” after.