Take crate2 of crate1 before opening crate1 is allowed

I am trying to create a scenario where you have crate2 on top of create1.
Both can be opened but they are both currently closed.

I can take crate2 of crate1 and open and close both.

The problem is when crate2 (top) is still on crate1 (bottom) I can open crate1 (bottom) without taking crate2 (top) first.

Below is the code I am using but don’t know how to get this resolved.

Crate4 is a container. It is unopenable and closed. It is lockable and unlocked. It is in the Alleyway.
There is a enterable container called Crate4's interior. [interior]
It is part of Crate4.
Crate4's top is a supporter.
There is a supporter called Crate4's top.
Crate5 is a container on Crate4's top in the Alleyway.
It is openable and closed. It is lockable and unlocked. 
After taking Crate5 of Crate4's top:
	say "I need to take the top crate of the bottom crate.";
	now Crate4 is openable and closed.

There might be a much easier way, I don’t know.

I think I solved it:

Crate4 is a container. It is unopenable and closed. It is lockable and unlocked. It is in the Alleyway.
There is a enterable container called Crate4's interior. [interior]
It is part of Crate4.
Crate4's top is a supporter.
There is a supporter called Crate4's top.
Crate5 is a container on Crate4's top in the Alleyway.
It is openable and closed. It is lockable and unlocked. 

Instead of taking Crate4:
	say "I need to take the top crate of the bottom crate.";

After taking crate5:
	say "now I can open the bottom crate.";
	now crate4 is openable.	

Can someone confirm and let me know.

No, there’s not a much easier way. Trying to hybridize supporters and containers is always a pain.

You’ve created 4 things here: Crate4, Crate4’s interior (which is a part of Crate4), Crate4’s top (which is a thing that’s completely independent of Crate4 and just happens to be named “Crate4’s top”), and Crate5.

The room description will mention both Crate4 and Crate4’s top since they’re separate things.

One can put things on Crate4’s top despite Crate5 covering it.

Since crate4 begins as unopenable, open crate4 gives “It isn’t something you can open” rather than referring to being unable to open it because it’s covered.

If you take crate5 and then put crate5 on crate4's top one can still then open crate4.

Getting this right is actually kind of advanced. Two possibilities are having separate container and supporter things for each crate and swapping them in and out for each other as needed or making crate a kind of object that has a container part and a supporter part. Both approaches would involve customizing basically every action that deals with a container or supporter, and thus requires a lot of familiarity with how the existing actions work and what the corresponding rules are. Also, having containers as parts of a thing can have weird interactions with light.

If you keep at this problem, you will learn a whole heck of a lot about Inform 7. If you don’t want to invest a lot of time and effort learning more details about Inform 7 right now and would prefer to get on with your current game, you might want to change the concept to something not involving hybridizing supporters and containers.

Zed is 100% right about all of this, except maybe about there not being a much easier way, because you can always just sidestep Inform’s robust world model and do a sloppy manual hack! This is definitely not the best practice, but I, er, know a few authors who wouldn’t be averse to a quick and dirty approach like this, especially if all you need to do is implement this single puzzle. Here’s a sketched-out approach:

Warehouse is a room.  "This is a mostly-empty warehouse.  You see two crates -- let's call them [crate1] and [crate2] -- [if crate2 is blocked]stacked, with the first resting on top the second[otherwise]sitting next to each other on the ground[end if]."

A container is either blocked or unblocked.  A container is usually unblocked.

Crate1 is a closed openable container in the warehouse.  It is fixed in place.  The description is "An unremarkable crate[if crate2 is blocked] resting on a second unremarkable crate[end if]." The cake is in crate1.  

Crate2 is a closed openable container in the warehouse.  It is fixed in place.  It is blocked. The description is "An unremarkable crate[if crate2 is blocked] stacked under a second unremarkable crate (except we're calling that other one the first crate just to avoid confusion)[end if]."The pinata is in crate2.

Instead of opening crate2 when crate2 is blocked:
	Say "You can't get it open when the first crate is on top of it!"
	
Instead of taking or pushing or pulling crate1 when crate2 is blocked:
	Say "You strain your muscles to heave the top crate off the bottom one, breaking up the stack.";
	Now crate2 is unblocked.

Again, this is a risky approach, because it’s much more fragile and less flexible than doing things the right way – in this implementation, the description of how the crates relate to each other is hard-coded into the warehouse description, so they can’t actually be taken out of the warehouse. If you need them to be movable, that’s more work since otherwise the description will get messed up! So definitely use this kind of thing with care (and make sure it gets tested!)

1 Like

If you’re not doing a major physics implementation, you can use Inform 7’s natural proclivities to your advantage.

Laboratory is a room.

A crate is a kind of openable container. It is usually closed. The description is usually "A wooden box with a hinged lid on the top." Understand "lid" as a crate.

A massive crate is a crate in Laboratory. Massive crate is fixed in place. "A massive crate sits against one wall."
A smaller crate is a crate in Laboratory. "A smaller crate sits atop the massive crate." Understand "small crate" as smaller crate.

[Note the intial appearance description only shows until an item has been moved by the player.]

Before opening massive crate:
	if we have not taken smaller crate:
		say "That smaller crate is sitting on top of the massive crate's lid. You'll need to move it first." instead.
Transcript
Laboratory
A massive crate sits against one wall.
 
A smaller crate sits atop the massive crate.
 
>x crate
Which do you mean, the massive crate or the smaller crate?
 
>massive
A wooden box with a hinged lid on the top.
 
>x smaller
A wooden box with a hinged lid on the top.
 
>look in massive crate
You can't see inside, since the massive crate is closed.
 
>open it
That smaller crate is sitting on top of the massive crate's lid. You'll need to move it first.
 
>take smaller
Taken.
 
>drop it
Dropped.
 
>l
Laboratory
A massive crate sits against one wall.
 
You can also see a smaller crate (closed) here.
 
>open massive
You open the massive crate.
 
>look inside
You see nothing unexpected in that direction.
 
>look in massive crate
The massive crate is empty.
 
>how disappointing...

This doesn’t let the player put the smaller crate back on the massive crate, but that’s a fussy detail that isn’t important unless the game is about stacking different crates to climb to a window.

2 Likes

Thanks for all your reply’s and help.

That second string of code I put up works fine for what I am trying to achieve.

I will, however, still play around with it to see what else I can get out of it.

Thanks again.

Good point re initial appearances! I overlook those all the time for anything except people, and should really wrap my brain around them…

1 Like