The behavior of the .copy() method of classes seen in Inform 6.31 and Inform 6.33 does not seem to match the description given on DM4 p. 66 (online: DM4 §3: Objects and classes ), which seems to indicate that only properties (and possibly only attributes relevant to the class for which the method is invoked) will be copied. Specifically, the passage:
It’s rather useful that recreate and copy can be sent for any instances, not just instances which have previously been created. For example,
Plant.copy(Gilded_Branch, Poison_Ivy)copies over all the features of aPlantfromPoison_IvytoGilded_Branch, but leaves any other properties and attributes of the gilded branch alone.
However, it appears that this is not the entire story. In the following test code, two classes (SmallContainer and Battery) are set up that both derive from a third (Treasure):
Demonstration Code
Constant Story "Copy Oddness";
Constant Headline "^Unexpected changes to attributes and properties when using .copy()?^";
Include "Parser";
Include "VerbLib";
Include "Grammar";
Class Room
has light;
Class Treasure
with value 5;
Class SmallContainer
class Treasure
with capacity 20
has container open ~openable ~lockable ~locked ~transparent ~enterable;
Class Battery
class Treasure
with capacity 50;
Battery battery1 "platinum fuel cell" selfobj
with name 'platinum' 'fuel' 'cell' 'battery',
before
[;
Wave:
Treasure.copy(self, golden_bucket);
]
has transparent;
Room Start "Starting Point"
with description
"An uninteresting room.";
SmallContainer golden_bucket "golden bucket" Start
with name 'golden' 'gold' 'bucket';
Verb 'squint'
* 'at' noun -> Squint;
[ SquintSub ;
print "^============================================";
print "^", (name) noun;
print "^container:", (TorF) (noun has container);
print "^lockable:", (TorF) (noun has lockable);
print "^locked:", (TorF) (noun has locked);
print "^open:", (TorF) (noun has open);
print "^openable:", (TorF) (noun has openable);
print "^transparent:", (TorF) (noun has transparent);
print "^value:", noun.value;
print "^capacity:", noun.capacity;
print "^ofclass Treasure: ", (TorF) (noun ofclass Treasure);
print "^ofclass SmallContainer: ", (TorF) (noun ofclass SmallContainer);
print "^ofclass Battery: ", (TorF) (noun ofclass Battery);
print "^============================================^";
];
[ TorF p ;
if (p)
print "TRUE";
else
print "FALSE";
];
[ Initialise ;
location = Start;
];
A call to Treasure.copy(BatteryInstance, SmallContainerInstance) seems to do the following:
- copy the value of the
.capacityproperty, despite the fact that this property is not declared inTreasureand despite the fact thatBatteryhas its own declaration - copy the (set) values of the
containerandopenattributes, despite the fact that these attributes are not set forTreasure - copy the (unset) value of the
transparentattribute, despite the fact that this attribute is not set forTreasureand that the specific instance is declared with that attribute set
> SQUINT AT CELL
============================================
platinum fuel cell
container:FALSE
lockable:FALSE
locked:FALSE
open:FALSE
openable:FALSE
transparent:TRUE
value:5
capacity:50
ofclass Treasure: TRUE
ofclass SmallContainer: FALSE
ofclass Battery: TRUE
============================================
> WAVE IT
You look ridiculous waving the platinum fuel cell.
> SQUINT AT CELL
============================================
platinum fuel cell
container:TRUE*
lockable:FALSE
locked:FALSE
open:TRUE*
openable:FALSE
transparent:FALSE*
value:5
capacity:20*
ofclass Treasure: TRUE
ofclass SmallContainer: FALSE
ofclass Battery: TRUE
============================================
Is the DM4 simply in error about the way that this method works, or has the way it works been changed since the time of original publication? If so, is there a more detailed description of the actual current function elsewhere?