Transforming one object into another

Hi…I’m trying to find an easy way to transform one object into another, and the examples I’ve found in the manuals involving magic words and machines don’t help much in the way of examples for this situation. Let’s say I want a room thats a lawn, and there are some leaves scattered on the ground. I’d like the player to be able to take a rake and rake them into a pile, and transform them into a pile of leaves which can then be picked up. Any suggestions on how to do this? Thanks in advance again!

For simple things, I’d probably just do something along the lines of

To transform (original - a thing) into (replacement - a thing):
	let position be the holder of the original;
	remove the original from play;
	now the replacement is in position.

In an earlier thread where I tried to do this a bit more systematically, Erik Temple wrote the following, which I think may be closest to what you’re looking for.

A thing has a thing called the replacement.
	
Replacing something is an activity.

For replacing something (called the original):
	let place be the holder of the original;
	let replacement be the replacement of the original;
	if the original holds something:
		if the replacement is a repository:
			repeat with item running through things enclosed by the original:
				now the item is held by the replacement;
		otherwise:
			repeat with item running through things enclosed by the original:
				now the item is held by the place;
	remove the original from play;
	move the replacement to the place.
	
To decide whether (item - an object) is a repository:
	if the item is a container, yes;
	if the item is a supporter, yes;
	if the item is a person, yes;
	no.
	
[Some command variations to allow flexibility for users]
	
To switch (original - a thing) for its replacement:
	carry out the replacing activity with the original.

To switch (original - a thing) for (replacement - a thing):
	change the replacement of the original to the replacement;
	carry out the replacing activity with the original.

[Examples of customization]

[A chest that is wired to explode, destroying everything inside it]
The chest is a container. The replacement is debris.

Before replacing the chest:
	repeat with item running through things contained by the chest:
			remove item from play.
	
[We have containers that become supporter-containers--a chest that is transformed into a sideboard, for example, with a drawer as part of the sideboard. We prefer that any contents in the chest go into the drawer, rather than onto the top of the sideboard (i.e., onto the supporter)]

Before replacing a container (called the original):
	if the replacement of the original is not a container:
		if the replacement of the original incorporates a container:
			repeat with item running through the things contained by the original:
				move item to a random container incorporated by the replacement of the original.

Pretty nice general method here. It lets you transform not only one object into another, but handles transference of contents and other situations without complaint. Most situations, anyway; I can imagine a few situations where it would need fine-tuning.

This example, while not as elegant, mostly does what I want it to do (i.e. not let the player take some leaves until they have raked them into a pile first.) But I wish I could figure out a way for Inform7 to create a new “pile of leaves” which the player can pick up after raking the leaves on the lawn. Right now all I can figure out is how to add some leaves to their inventory after raking them. I would just like to be able to create a new pile instead.

[code]The Yard is a room. “You’re near a grassy lawn.”

There is a rake in the Yard.

A thing can be raked or not raked.

There is some leaves in the Yard. “Some leaves have fallen from the old tree and are scattered across the lawn.” The some leaves are a thing. The some leaves are not raked.

Raking is an action applying to one thing. Understand “rake [thing]” as raking.

Instead of taking the some leaves:
say “There’s too many to pick up all at once.”.

Check raking:
if the rake is not held:
say “You’ll need a rake to do that.”;
rule fails.

Check raking:
if the rake is held:
say “You rake the leaves into a small pile (and then gather some up in your arms).”;
now the some leaves are carried by the player;
rule succeeds.
[/code]

I think you’re almost there. Why not say “Instead of taking leaves when the leaves are not raked?” Then you’ll be able to take them normally any time.

You can also have the description and the printed name of the leaves depend on their state: “[if raked]pile of[otherwise]scattered[end if] leaves”

Hmm. I generally put anything deliberately carried out by an action in the “carry out” section of the rulebook. Leaving it under checking means that it may be carried out when it shouldn’t be.

Also, be really, really careful that you’re not creating unintended consequences. Right now, even if the player is in the middle of space, if he types “rake computer” while holding a rake, he’ll still get the leaves. You probably want to limit this response to only raking leaves.

(It might also interest you to know that you don’t explicitly have to declare that things are things: “There are some leaves in the Yard” makes that assumption.)

There’s quite a few different ways to do this, but the easiest is to create a “pile of leaves” object and then “move the pile of leaves to the location” at the appropriate time. You may also want to “remove the leaves from play” at the same time.

Inform doesn’t always play well when things have similar names, so I’d recommend using loose leaves and pile of leaves to make sure it doesn’t get confused. There’s other options, but this one is pretty straightforward.

If you wanted to keep one object, these changes to your code would be one way of doing it:

[code]“Rake!”

The Yard is a room. “You’re near a grassy lawn.”

There is a rake in the Yard.

There are some leaves in the Yard. “Some leaves have fallen from the old tree and are scattered across the lawn.” The leaves can be raked or not raked.

Understand “pile of” and “pile” and “piled” and “piled up” as the leaves when the leaves are raked.
Understand “raked” as the leaves when the leaves are raked.

The leaves are not raked.

Before printing the name of the leaves:
if the leaves are raked:
say "piled up ";

Raking is an action applying to one thing. Understand “rake [something]” as raking.

Check taking the leaves:
if the leaves are not raked:
say “There’s too many to pick up all at once.” instead.

Check raking:
if the rake is not held:
say “You’ll need a rake to do that.” instead;

Check raking:
if the noun is not the leaves:
say “There’s a small note on the rake: ‘For use with leaves ONLY.’” instead.

Check raking the leaves:
if the leaves are raked:
say “The leaves are already in a nice pile.” instead.

Carry out raking:
say “You rake the leaves into a small pile (and then gather some up in your arms).”;
now the leaves are carried by the player;
now the leaves are raked.[/code]

Thanks so much for this example it explains a lot!