I7: property scales conversion.

Hello all,

I am pretty new to IF and I really like the Inform7 language for it’s expressiveness and beauty. So I’m doing some random tests at the moment as well as reading the fine documentation. But until now there were mentioned 6.6. Whereabouts on a scale? But how do I convert a property acording to that scale? Can I7 do that for me?

Here is an example with a simple property hunger level (it should decrease every turn, but that’s an other subject). I’ve managed to get a solution for printing the apparent hunger of person, when it’s examined. But I think this not quite elegant.

[code]“Hunger”

A person has a number called hunger level. The hunger level of a person is usually 10.

Definition: a person is starving if its hunger level is 0.
Definition: a person is hungry if its hunger level is 5 or less.
Definition: a person is saturated if its hunger level is 7 or less.
Definition: a person is well-fed if its hunger level is 9 or less.
Definition: a person is abundant if its hunger level is 10.

Instead of examining a person (called p):
say "[The noun] seem[if the noun is not the player]s[otherwise][end if] to be ";
if p is starving:
say “starving”;
else if p is hungry:
say “hungry”;
else if p is saturated:
say “saturated”;
else if p is well-fed:
say “well-fed”;
else:
say “abundant”

The player is starving.

The yard is a room. Alice, Bob, Eve, Marvin are persons in the yard. Alice is abundant. Bob is well-fed. Eve is saturated. Marvin is hungry.[/code]

Any opinions or hints are appreciated.

Cheers,
Thul

The ideal is to use a kind of value. I can’t recall offhand, but as far as I remember, Inform 7 doesn’t let you associate kinds of value with numbers: for that, you’ll need a numbered kind of value, as seen in Writing with Inform, Chapter 4.9. (Using new kinds of value in properties). As you discovered, definition adjectives can’t be easily printed like kinds of value.

Essentially, we want to associate a number to every person and then use that number to print out the actual hunger. Given that, we lose a bit of elegance. Still, I think this would be easiest done using tables.

[code]Hunger is a kind of value. The hungers are starving, hungry, peckish, satiated, and overfed. A person has a number called hunger value. The hunger value of a person is usually 8.

Table of Hunger Levels
hunger threshold (number)
starving 0
hungry 5
peckish 7
satiated 9
overfed 10

To decide which hunger is the hungriness of (sufferer - a person):
repeat through the Table of Hunger Levels in reverse order:
if the threshold entry is at most the hunger value of the sufferer, decide on the hunger entry.

To set (actor - a person) as being (actor’s hunger - a hunger):
choose the row with a hunger of the actor’s hunger in the Table of Hunger Levels;
now the hunger value of the actor is the threshold entry.
[For borderline hackish syntax, change the phrase header to "To now/-- (actor - a person) feels (actor-hunger - a hunger). This lets you write things like “now the player is overfed” and pretend you’re referencing a kind of value belonging to the player. Given that I7 flatly discourages a regular “To now” - syntax, I feel this is all kinds of inelegant, but your mileage may vary.]

To feed (actor - a person):
increase the hunger value of the actor by one.

To starve (actor - a person):
decrease the hunger value of the actor by one.

After examining a person, say “[The noun] look[if the noun is plural-named]s[end if] [hungriness of the noun].”

When play begins: set the player as being overfed.
Every turn: starve the player.
The yard is a room.[/code]

There’s probably a better, more idiomatic way, but I’m not seeing it at the moment. Another way to do it is shown in Chapter 9, in the example called MRE.

Thank you very much for the detailed example. Despite the fact I’ve not been that far with my crawling through the documentation, I see again the beauty of I7. Thus, I should keep on crawlin’. And that’s exactly, what I’ll do now. :slight_smile:

Cool. Don’t be afraid to try to improve on this. I’m sure it could be made more concise and expressive. That said, do try to avoid getting stuck on the “code” part of the game – the writing is the important bit, and the difficult one.