Combining the same object?

This seems to work when the Drops are different types of spells; when they’re the same, the action is allowing the noun and the second noun to be the same object. For example, if there is one Blizzard Drop in the room, it casts itself, changes to a Blizzara Drop and then disappears to nowhere. Any help is very appreciated.

[code]The Testing Room is a room.

Magic is a kind of thing.

Element is a kind of value.
The elements are Ice, Flame, and Electricity.
A magic has an element.

A Drop is a kind of magic.
A spellname is a kind of value.
A Drop has a spellname.
Before printing the name of a Drop: say "[spellname] ".
Before printing the plural name of a Drop: say "[spellname] ".
Understand the spellname property as describing a Drop.

Understand “cast [thing] at [thing]” as combining. Combining is an action applying to two things. Check combining: if the noun is not a drop, say “You can only cast spells.” instead.

Carry out combining:
repeat through the Table of Second Level Spells:
if the noun is the first spell entry:
if the second noun is the second spell entry:
now the spellname of the second noun is the resulting spell entry;
say “The drops combine into a [spellname of the second noun] Drop.”;
now the noun is nowhere;
rule succeeds;
say “You can’t combine those drops!”;
stop the action.

Blizzard, Blizzara, Blizzaga, and Blizzaja are spell names.

In the Testing Room are 2 Blizzard Drops.

Table of Second Level Spells
first spell second spell element resulting spell
Blizzard Blizzard Ice Blizzara[/code]

The problem is that all your Blizzard Drops are indistinguishable (there’s nothing the player can do to tell the game that she wants one of the Blizzard Drops rather than another), and when that happens, Inform always picks the same indistinguishable object. (I think that somewhere in the internals it’s defined all the objects and it picks the first one that matches.)

A solution to this is to try to check beforehand if you’re trying to combine a drop with itself, and manually redirect it so the second noun is a different drop of the same type that the player can touch, if possible:

[code]The Testing Room is a room.

Magic is a kind of thing.

Element is a kind of value.
The elements are Ice, Flame, and Electricity.
A magic has an element.

A Drop is a kind of magic.
A spellname is a kind of value.
A Drop has a spellname.
Before printing the name of a Drop: say "[spellname] ".
Before printing the plural name of a Drop: say "[spellname] ".
Understand the spellname property as describing a Drop.

Understand “cast [thing] at [thing]” as combining it with. Combining it with is an action applying to two things. Check combining: if the noun is not a drop, say “You can only cast spells.” instead.

Similarity relates a drop (called X) to a drop (called Y) when X is not Y and the spellname of X is the spellname of Y. The verb to be similar to means the similarity relation.

Before combining when the noun is the second noun:
if a touchable drop (called new drop) is similar to the noun:
try combining the noun with the new drop instead;
otherwise:
say “You need two of those drops to do that.” instead.

Carry out combining:
repeat through the Table of Second Level Spells:
if the noun is the first spell entry:
if the second noun is the second spell entry:
now the spellname of the second noun is the resulting spell entry;
say “The drops combine into a [spellname of the second noun] Drop.”;
now the noun is nowhere;
rule succeeds;
say “You can’t combine those drops!”;
stop the action.

Blizzard, Blizzara, Blizzaga, and Blizzaja are spellnames.

In the Testing Room are 5 Blizzard Drops.

Table of Second Level Spells
first spell second spell element resulting spell
Blizzard Blizzard Ice Blizzara

Test me with “cast blizzard at blizzard/g/g/l”.[/code]

Note that I tweaked your action name a bit so it’s possible to say “combining the noun with the new drop”–if you don’t make the name “combining it with” then you wind up having to same “combining the noun the new drop” because Inform doesn’t know what preposition to use.

(This is sort of based on the teacup code here, when I had a bunch of indistinguishable teacups and had to make sure that the game tried to fill empty teacups that weren’t in the cabinet, instead of filling the same teacup over and over.)

Thanks Matt, that works great.