I’m very new to the Inform programing language, and I was wondering if it’s possible to create a room inside another room.
Here is some of my current code:
The mall is a room. The description of a mall is "A busy mall."
The electronics store is a room in the mall. The description of the electronics store is "A store."
The book store is a room in the mall. The description of the book store is "A store."
My desired output:
A busy mall.
>enter electronics store
>enter book store
My current code gives a contradiction error.
Creating one room inside another is easy enough, since “inside” and “outside” are directions that Inform understands. Putting more than one room inside another is more complicated, since only one can be in the “inside” direction.
The idea is to create enterable containers representing the various stores. When the player enters one, they are immediately moved to the corresponding room. (See Tamed in the Recipe Book.)
Although we can’t make all the stores “in” from the mall, there’s no problem with having the mall “out” from all the stores. I do that using a “when play begins” rule, but it could just as well be hard-coded.
A store is a kind of room.
A storefront is a kind of scenery enterable container.
Fronting relates one storefront to one store. The verb to front means the fronting relation.
Understand "[something related by fronting]" as a storefront.
For printing the name of a storefront:
let S be a random store fronted by the item described;
say "[the printed name of S in lower case]".
After entering a storefront:
let L be a random room fronted by the noun;
move the player to L;
When play begins: [so that "exit/go out" will work]
repeat with S running through stores:
let F be a random storefront fronting S;
now the location of F is mapped outside S.
The Mall is a room. "A busy mall."
The Book store is a store. "A store." The book store is inside from the mall.
The book_store is a storefront in the mall. The book_store fronts the book store.
The Electronics store is a store. "A store."
The elec_store is a storefront in the mall. The elec_store fronts the electronics store.
You might want to stop the player treating storefronts like normal containers. Stopping them from putting things in is easy:
Check inserting something into a storefront: say "You'll have to go in first." instead.
But preventing this:
>take all from book store
The book store is empty.
is horribly tricky, and I don’t see a good way of doing it offhand. I can think of several bad ways, which might be OK in practice. Maybe someone else can suggest something reasonable. [Ideally, trying to loot a storefront would prompt a different message than trying to take all from an empty crate, say, in the same location. But I don’t know a way of finding out which container the parser understood the player to be taking all from. Action variables are not set.]
This will do it without any worries of colliding with container behaviors:
The mall is a room. "A busy mall."
The electronics store is south of the mall. "An electronics store." The mall is outside of the electronics store.
The book store is west of the mall. "A book store." The mall is outside of the book store.
Inside of the mall is nowhere.
The electronics-store-scenery is scenery in the mall. It is privately-named. The printed name is "electronics store". Understand "electronics/store" as the electronics-store-scenery.
Instead of entering the electronics-store-scenery:
try going south;
The book-store-scenery is scenery in the mall. It is privately-named. The printed name is "book store". Understand "book/store" as the book-store-scenery.
Instead of entering the book-store-scenery:
try going west;