Selectively hide (but allow interaction) things in container

I would like to selectively hide (but allow interaction with) a specific thing in a container. Here is an example below. It will always remain hidden but usable. It will never leave the container.

I considered making it a part of the chest, but I want it to act as a container inside a container. For example. when the chest is closed, I do not want to allow access the the secret compartment.

[code]“Magic Chest”

The stage is a room

A container called the magic chest is in the stage. It is open, openable. The carrying capacity is 2. The description is “A small wooden chest.” A container called the secret compartment is in the chest. It is closed, openable. The carrying capacity is 1.

A thing called a ball is in the stage.

Test me with “take chest / put ball in chest / x chest / i / open secret / put ball in secret / close secret / x chest / i / close chest / open secret”[/code]

This is the output…

>[1] take chest
Taken.

>[2] x chest
A small wooden chest.
In the magic chest is the secret compartment.

>[3] i
You are carrying:
  the magic chest (open)
    the secret compartment (closed)

>[4] put ball in chest
(first taking the ball)
You put the ball into the magic chest.

>[5] x chest
A small wooden chest.
In the magic chest are a ball and the secret compartment.

>[6] i
You are carrying:
  the magic chest (open)
    a ball
    the secret compartment (closed)

>[7] open secret
You open the secret compartment.

>[8] put ball in secret
(first taking the ball)
You put the ball into the secret compartment.

>[9] close secret
You close the secret compartment.

>[10] x chest
A small wooden chest.
In the magic chest is the secret compartment.

>[11] i
You are carrying:
  the magic chest (open)
    the secret compartment (closed)

>[12] close chest
You close the magic chest.

>[13] open secret
You can't see any such thing.

This is what I WHAT the output to look like…

>[1] take chest
Taken.

>[2] x chest
A small wooden chest.

>[3] i
You are carrying:
  the magic chest (open but empty)

>[4] put ball in chest
(first taking the ball)
You put the ball into the magic chest.

>[5] x chest
A small wooden chest.
In the magic chest is a ball.

>[6] i
You are carrying:
  the magic chest (open)
    a ball

>[7] open secret
You open the secret compartment.

>[8] put ball in secret
(first taking the ball)
You put the ball into the secret compartment.

>[9] close secret
You close the secret compartment.

>[10] x chest
A small wooden chest.

>[11] i
You are carrying:
  the magic chest (open but empty)

>[12] close chest
You close the magic chest.

>[13] open secret
You can't see any such thing.

Any recommendations as to how to do this will be much appreciated.

I’d recommend starting the secret compartment off-stage, then moving it to the chest when the player learns where it is/finds how to open it/opens it for the first time. It’ll make the coding far easier and remind the player if they come back to it later.

Or starting it off-stage and then making it part of the chest when the chest is open. Flipping it in and out like that violates my usual principle of “minimal state” – it would be embarrassing if the part-of-chest state got out of sync with the chest-open state. But it simplifies everything else, and you can implement it without much complexity.

(Unless your game features a complex chest-opening machine, in which case, well, it will get complicated. :slight_smile:

Thanks for your answers. In this case, the off stage trick will not work for my problem the way I need it too, but I think I found a good solution. I decided to make it a part of the chest after all, and then conceal it, if the chest is closed. I haven’t done a lot of testing yet, but this looks promising…

[code]“Magic Chest”

The stage is a room

A container called the magic chest is in the stage. It is open, openable. The carrying capacity is 1. The description is “A small wooden chest.” A container called the secret compartment is part of the chest. It is closed, openable. The carrying capacity is 1.

Rule for deciding the concealed possessions of the chest:
if the particular possession is the secret and the chest is closed, yes; otherwise no.

A thing called a ball is in the stage.

Test me with “take chest / x chest / i / put ball in chest / x chest / i / x secret / open secret / put ball in secret / close secret / x chest / i / close chest / open secret”[/code]

>[1] take chest
Taken.

>[2] x chest
A small wooden chest.

>[3] i
You are carrying:
  the magic chest (open but empty)

>[4] put ball in chest
(first taking the ball)
You put the ball into the magic chest.

>[5] x chest
A small wooden chest.

In the magic chest is a ball.

>[6] i
You are carrying:
  the magic chest (open)
    a ball

>[7] x secret
You see nothing special about the secret compartment.

>[8] open secret
You open the secret compartment.

>[9] put ball in secret
(first taking the ball)
You put the ball into the secret compartment.

>[10] close secret
You close the secret compartment.

>[11] x chest
A small wooden chest.

>[12] i
You are carrying:
  the magic chest (open but empty)

>[13] close chest
You close the magic chest.

>[14] open secret
You can't see any such thing.

Thank again for your time and ideas. Always appreciated!