How about moving a noun to a location inside a container in that location?

Does anyone know how to move a noun to a location inside a container?

Everything except the first ‘if’ below works:

Carry out transforming:
If the player is not the noun and a container holds the player:
Move the noun to the container;
Now the player is the noun;
Say “You transform inside the container!”;
Now every NPC that is not the player is nowhere;
Otherwise if the player is not the noun:
Now the noun is in the location of the player;
Now the player is the noun;
Say “In a spray of mist, you transform!”;
Now every NPC that is not the player is nowhere;
Otherwise if player is the noun:
Say “You already are.”;
Otherwise:
Continue the action.

I just noticed that it stopped working if the player was in or on something. I could make these things that the player is in or on separate rooms, but sometimes there is an elegant way, that I just don’t know yet.

Thanks!

Hey Dan,

When you post actual code like this, you can highlight it at the editing stage and click the ‘preformatted text’ button (looks like </>… or you can press Command-E, or Alt-E on PC?) to format it so all the tabs and indents are preserved. That makes it easier for people to read, and also lets them copy-paste it straight into Inform or whatever program.

That said, I’d probably need to review your previous post about this action to follow this. I haven’t yet, but I can see in your code there are distinctions you can benefit from.

“the location of the player” always returns the room that has the player in it. Even if the player’s in a basket in a box in a safe in that room, “the location of the player” still gives the room. That’s affecting some of your code. Where you’ve put “Now the noun is in the location of the player”, that’s probably not doing what you thought it was doing.

You can use “the holder of the player” to get the object or room that is directly enclosing the player. There’s an example I just bumped into in the documentation called Swigmore U that shows how to use “the holder” to identify something the player is on top of, and move something else to that same spot. An excerpt:

if the player is on a perch (called the awkward position): 
         let place be the holder of the awkward position; 
         move the noun to the place;

This might enough info to get you going for now.

-Wade

2 Likes

It might be that the phrase you’re looking for is the holder of the player. If the player is not enclosed by anything other than a room, than the holder of the player will be that room; if the player is subcontained by a container or supporter, that container or supporter will be the holder of the player.

So you can write move the noun to the holder of the player to get the item to wherever the player is.

2 Likes

This is exactly what I was talking about in my anniversary post.

Friendly and helpful response to a question while giving a nudge towards more reader/fellow programmer-friendly layout to the original poster.

And then still answering the question to the best of your ability.

Tip of the hat to you, Wade.

Rovarsson

2 Likes
If the player is not the noun and a container holds the player:
     Move the noun to the container;

I thought it might be helpful to elucidate one issue in the code you posted, which the example Wade posted implicitly fixes, since it’s something that gave me some trouble when learning Inform! The reason this bit doesn’t work is that Inform doesn’t know what container you mean in line 2. In line 1, it’s just testing whether the condition applies, and when it sees that it does, it just moves to line 2. But as far as line 2 is concerned, “the container” could be any container. The way around this is the “calling” command. That’s why the excerpt Wade posted has that parenthetical “(called the awkward position)” in the if statement – that creates a variable you can use through the rest of the rule, allowing it to be referenced in line 2.

So in your code, you’d just tweak it like this:

If the player is not the noun and a container (called the foo) holds the player:
     Move the noun to the foo;
3 Likes

Thought it would be something simple, but boy was that simple. Holder of the player is what I needed!

1 Like

And cleaned it up. Since holder of the player can also be their room location, did not need the second if statement. Now that this is solved, getting close to publishing it. Thanks!

2 Likes

Why thank you Rovarrson. I’d like to think the days when I’d charge out of my house screaming and waving a cricket bat at the sight of a stranger are far behind me now.

Wade

4 Likes

Glad to be helpful!