I’ve been having some trouble with creating compilable code that includes variables that are preset for some kinds of things but determined by formula for other kinds of things. The matter is a bit complex and I think an example rather than an attempt at explanation will best demonstrate what I’m talking about.
Let’s say we have a game world in which every possible thing will have a numeric value called weight, and that this value may change over time for some objects under some circumstances. We wish to stipulate the weight of some (probably) static things when defining them, while writing rules that will derive or adjust the weight of other things according to current conditions. Setting aside all other particulars of the following example not directly related to this question (such as the various superior ways to determine the gross and net weights of an item, or whether the whole scenario is unnecessarily complex and contrived) let’s say we wrote:
[code]A person has a number called vitality. The vitality of a person is usually 5.
A thing has a number called weight. The weight of a thing is usually 1. The weight of a person is usually 150.
The description of a thing is usually “Fascinating. [The noun] [unless the noun is the player]weighs[otherwise]weigh[end if] [weight of the noun] pounds.”.
The Batting Cage is a room. The description of the Batting Cage is “Surrounded by a thick canvas backdrop, the team has gathered here for batting practice.”.
Persuasion rule: persuasion succeeds.
A man called Jeff is in the Batting Cage. The player is Jeff. The vitality of Jeff is 6.
A man called Sam is in the Batting Cage. The vitality of Sam is 8.
A woman called Carol is in the Batting Cage.
A bowling ball is in the Batting Cage. The weight of the bowling ball is 14.
A baseball bat is in the Batting Cage. The weight of the baseball bat is 2.
A ring is in the Batting Cage. The description of the ring is “A practice weight that fits onto a baseball bat. It is generally believed that swinging a bat with the weight attached will increase the power of a batter’s swing. This ring weighs 2 pounds.”. The weight of the ring is 2.
Instead of an actor putting something on the baseball bat:
unless the noun is the ring:
say “Let’s stay focused here.”;
otherwise:
if the second noun incorporates the ring:
say “The ring is already on the bat.”;
otherwise:
now the ring is part of the baseball bat;
increase the weight of the baseball bat by 2;
say “[if the actor is the player]You place[otherwise][The actor] places[end if] the ring on the bat.”.
Instead of taking the ring:
if the noun is incorporated by the baseball bat:
move the noun to the actor;
decrease the weight of the baseball bat by 2;
say “[if the actor is the player]You remove[otherwise][The actor] removes[end if] the practice ring from the bat.”;
otherwise:
continue the action.
The block swinging rule is not listed in the check swinging rulebook.
Check an actor swinging:
unless the noun is the baseball bat:
say “Let’s stay focused here.” instead.
After an actor swinging the baseball bat:
if the noun incorporates the ring:
increase the vitality of the actor by 1;
if the vitality of the actor is greater than 10:
change the vitality of the actor to 10;
if the actor is the player:
say “You feel your muscles bulging after your workout.”;
continue the action;
otherwise:
say “[The actor]'s muscles are bulging after [if the actor is male]his[otherwise]her[end if] workout.”;
continue the action;
otherwise:
continue the action.
Report an actor swinging something:
if the actor is the player:
say “You swing the bat as the others study your technique.”;
otherwise:
say “[The actor] swings the bat as the rest of you study [if the actor is male]his[otherwise]her[end if] technique.”.[/code]
Wonderful. The code compiles and everything works as well as we might expect for such a simple scenario. However, we included the statement “A person has a number called vitality” and oddly referred to this number during the process of swinging the bat. Let’s say we later decide to put this obscure value to use and specify that “vitality” will determine a person’s bodyweight, but we want the weight of other things to remain their predefined value. Therefore we modify the code in the following way:
[code][Delete:]
The weight of a person is usually 150.
[Add:]
To decide what number is weight of (abc - a person):
let wvalue be the vitality of abc;
change wvalue to wvalue * 30;
decide on wvalue.[/code]
Inform doesn’t like this change, and tells us:
(with a similar message for “decrease the weight of the baseball bat by 2”).
Fine. We take a more direct approach, changing the two Instead rules for modifying the bat with the ring as follows:
[code][Delete:]
increase the weight of the baseball bat by 2;
[from the Instead of an actor putting something on the baseball bat rule, and replace it with:]
now the weight of the baseball bat is 4;
[Delete:]
decrease the weight of the baseball bat by 2;
[from the Instead of taking the ring rule, and replace it with:]
now the weight of the baseball bat is 2;[/code]
Inform doesn’t care for this either, and tells us:
Apparently then we will not be allowed to directly modify the weight of things that have a predefined weight if the weight of other things in the game-world is derived from a formula rather than directly defined.
I originally included the statement “The weight of a thing is usually 1” as a catch-all for things whose weight I didn’t care to define. If I eliminate this statement and replace it with a more complex decision process, such as:
To decide what number is the weight of (abc - a thing):
unless the weight of abc is 0:
decide on the weight of abc;
otherwise:
decide on 1.
Nothing changes and I get the same compiler error as last time. However this latest addition is problematic in itself, since if I comment out the two “now the weight of the baseball bat is” lines and then examine the bowling ball (for example), the test game rightly crashes with the message “Fatal Error: Stack Overflow” since I attempted to define the weight of something by referring to its weight.
It’s not helpful to delete the latest rule addition and replace it with a multitude of statements such as:
[code]To decide what number is the weight of (abc - a thing):
decide on 1.
To decide what number is the weight of the bowling ball:
decide on 14.[/code]
etc, since I really do want to change the weight of the baseball bat under some conditions and it would seem that no valid “decide” rule could properly address the weight of the baseball bat.
In theory one could deal with the general problem by giving everything two weights, a hidden weight and a usable weight. One could then write rules such as:
[code]The hiddenweight of the bowling ball is 14.
To decide what number is the weight of (abc - a thing):
unless the hiddenweight of abc is 0:
decide on the hiddenweight of abc;
otherwise:
decide on 1.
To decide what number is weight of (abc - a person):
let wvalue be the vitality of abc;
change wvalue to wvalue * 30;
decide on wvalue.[/code]
But a) this is surely an inconvenient and highly contrived method, and b) in fact a solution to the general problem is needed for some rather complex code that runs to tens of thousands of words, and modifying hundreds of lines of code that deal with weight to add a highly contrived “hidden weight” value is a proposition that arouses little enthusiasm.
If anyone has experience writing I7 code in which some general values of things:
a) are determined by formula in some cases but directly defined in other cases, and
b) must be altered under certain conditions
I would be very interested in hearing your insights into this issue. Thanks in advance for any responses.