Hi, I am new to Inform 7, and to creating IF games in general. I am running into problems having an item be part of another item, but still be something that can be taken. E.g. suppose I had a jar and a lid:
The jar is a thing in Basement. The lid is part of the jar.
Making the lid part of the jar makes it not get listed separately in the room, which is what I want, but it’s not takeable, being part of the jar. Is there any way to override this
I tried something like this to work around it:
Instead of taking the lid:
now the player carries the lid;
say “You take the lid.”
This works, but doesn’t change the fact that the lid is still part of the jar, and can be taken again.
Instead of taking the lid:
if the lid is part of the jar:
now the player carries the lid;
say “You remove the lid from the jar.”;
otherwise:
continue the action.
Instead of putting the lid on the jar:
if the lid is not part of the jar:
now the lid is part of the jar;
say “You put the lid on the jar.”;
otherwise:
continue the action.[/code]
Here’s another way to do it. You have to create a definition, but then you can use more specific and readable rule preambles, and you don’t need “continue the action.”:
[code]The lid is part of the jar.
Definition: a thing is attached rather than loose if it is part of something.
Instead of taking the attached lid:
now the player carries the lid;
say “You remove the lid from the jar.”;
Instead of putting the loose lid on the jar:
now the lid is part of the jar;
say “You put the lid on the jar.”;[/code]
I just noticed that both of these examples fail if you try to put the lid on the jar when it is already screwed on - the Instead rule does nothing, then a check rule causes you to take the lid successfully, then another check rule says “putting things on the jar would achieve nothing.” To deal with that, you need to add another case.
For Jim’s version, you could change a rule:
Instead of putting the lid on the jar:
if the lid is not part of the jar:
now the lid is part of the jar;
say "You put the lid on the jar.";
otherwise:
say "The lid is already screwed onto the jar."
For my version, you could add a rule:
Instead of putting the attached lid on the jar:
say "The lid is already screwed onto the jar."