Why can't I put a carrot in my refrigerator?

My fridge reads as empty on searches and examines, but I’ve told Inform there’s a carrot in the fridge.

I’ve used the “Kitchen” code from the Inform7 Documentation as follows:

A kitchen is a kind of room. 

West of the den is a kitchen.

A refrigerator is a kind of container. A refrigerator is usually closed and openable. A refrigerator is usually fixed in place. A refrigerator is usually scenery. Understand "fridge" as a refrigerator.

A refrigerator is in every kitchen. 

Inside the refrigerator is a carrot.

However, the following commands reveal no carrot!

>open fridge
You open the refrigerator.

>x fridge
The refrigerator is empty.

>take carrot
You can't see any such thing.

I would love to learn what I’m doing wrong or where I can learn about how to fix this.

Thank you!

Picture it this way. If you and I stand in front of a house that is full of kitchens, and every one of those kitchens has a refrigerator in it, and I say to you, ‘Please get me the carrot from the refrigerator,’ you’re probably going to respond: ‘Which refrigerator?’

That’s how Inform sees your code. You might have thought it could work out you meant the only refrigerator you’ve created, but it can’t make that assumption. Someone else is typing a post as I type this, so I’ll just wait to see what they’re going to say. It might save me bunch of a typing :slight_smile:



I’m not in front of my computer so I can’t check, but I think what’s happened is that you’ve created refrigerators as a kind - which is to say, you’ve told Inform there’s a general category of objects called refrigerators - and then told it one of these generic refrigerators exists in every room that’s a kitchen. But you haven’t created a specific one, so the reference to “the refrigerator” is confusing - I’m betting that if you check the index, you’ll find an offstage refrigerator that contains the carrot, because the compiler thought you wanted to create a new object.

If you want there to be multiple fridges, each with a carrot, you can create carrots as a kind and say that a refrigerator always contains a carrot. Or you could create a specific named fridge and put the carrot in that.

EDIT: not sure that was worth the wait :slight_smile:


Ahh, I see! That does make sense. Thank you.

So here’s a complete example:

The den is a room.

A kitchen is a kind of room. 

the main kitchen is a kitchen. It is west of the den.

A refrigerator is a kind of container. A refrigerator is usually closed and openable. A refrigerator is usually fixed in place. Understand "fridge" as a refrigerator.

the main refrigerator is a refrigerator in the main kitchen.

Inside the main refrigerator is a carrot.

You’ll note I had to make a particular kitchen (the main kitchen) and a particular fridge within it (the main fridge). That allows us to specify where the carrot is.

Note I also took out the line ‘A refrigerator is usually scenery.’ With that line in place, the fridge would be invisible when you entered the main kitchen. Now, you will be able to see it.



Ah–using the index is a great tip. I think I do see two kinds of fridges but not sure how to see if one contains a carrot. Will continue troubleshooting. I think I just tried naming the fridge but must be missing something upstream.

1 Like

Ahh, thank you! And thanks for the scenery tip, I was wondering why I was not seeing it.

I think I see–it goes something like: define a class, instantiate an object of that class. And no need for “A refrigerator is in every kitchen”, and I can probably keep that line out of my game because I’m not building a apartment complex or something with many kitchens that would benefit from that line’s reduction of overhead.

Yeah, you get the idea. You don’t even need to create a class first if you’re only going to have one of something. For instance, you could replace the ‘A refrigerator is a kind of container…’ line, and the one after, with:

The main refrigerator is a closed, openable container in the main kitchen. It is fixed in place. Understand "fridge" as the main refrigerator.

And the same goes for the kitchen being a kind of room. If you only have one kitchen, you can just say

The kitchen is west of the den.