I’m trying to define a single phrase that allows one to pass in the name of a property, associate that property with a specific list property of a different object, and then update the first property with values from the second. I’m almost there, but I’m stymied by what may be a bug in the treatment of type-casting (or just something I’m overlooking). Here’s a mini version of the set-up:
[code]Glulx color value is a kind of value. Some glulx color values are defined by the Table of Common Color Values.
Table of Common Color Values
glulx color value assigned number
g-black 0
g-white 16777215
An animation track is a kind of object.
An animation track has an object called the animation-target.
An animation track has a number called animation-length.
An animation track has a number called the property-storage.
An animation track has a list of glulx color values called the color-reel.
An animation track has a list of numbers called the numerical-reel.
A g-element is a kind of object.
A g-element has a glulx color value called the tint.
A g-element has a number called the numerical-value.
The default track is an animation track. The color-reel is {g-black, g-white, g-black, g-white}. The numerical-reel is {12, 6, 8, 10, 7, 3}.
The animatee is a g-element. The tint is g-white. The numerical-value is 5.
To animate (track - an animation track) targeting (P - a property) of (targ - an object):
now the animation-target of the track is targ;
let P1 be P converted to a number;
now the property-storage of the track is P1;
now the animation-length of the track is the number of entries in the reel-list appropriate to P of the track;[works, but can’t be printed–notice that the list-length is correct, however.]
say “The chosen list (length: [animation-length of the track]) is [the reel-list appropriate to (P1 as a property) of the track].”
To decide what number is (P - a property) converted to a number: (- {P} -).
To decide what property is (N - a number) as a property: (- {N} -).
To decide what list of glulx color values is the reel-list appropriate to (P - a glulx color value valued property) of (track - an animation track):
decide on the color-reel of the track.
To decide what list of numbers is the reel-list appropriate to (P - a number valued property) of (track - an animation track):
decide on the numerical-reel of the track.
There is a room.
When play begins:
animate the default track targeting the numerical-value of the animatee.[/code]
The problem is with the “reel-list appropriate to…” phrases. The intention is to have a stack of these phrases that can filter properties of different types to select the appropriate list property for that type. This works just fine if you pass in the property name directly (using the P variable in the “to animate…” block above): the stacked phrases pick out the right type. But if, as in the example above, you typecast the property to a number so you can store it for later use (P1 in the “to animate” block) and then try to typecast back to a property again, using “To decide what property is (N - a number) as a property: (- {N} -)”, Inform always matches to the first-defined phrase in that stack. What that means for the present example is that the color-reel is chosen instead of the numerical-reel.
In other words, when the property is typecast to a number and back again, Inform allows it to match as a specific “x valued property” in a phrase regardless of whether the property actually is of that type. Is there a way around this? Am I naively assuming that you can just typecast back to a property without some other bookkeeping?
I hope this is clear–it’s when writing up questions like these that I feel my lack of programming background most acutely… Thanks for any help!
–Erik