The Foxaroo tinkering around with Inform7

I’ve had to put my full-size project on hold due to unresolved health issues, but on my good days I love to tinker with Inform7 on a much smaller scale. Therefore I’ve started this thread to ask questions about things I occasionally get stuck on.

Although my first question is merely asking for confirmation. About creating scenes in Inform7… am I correct in my belief that to initiate any scene you need either:
a) a time mark,
b) a yes/no state, or
c) the ending of a prior scene?

That’s what I found in the manual: Eg: “when the player is in the Station for the third turn” and “when score is not the last score.”

I’ve searched the forums and found another participant has asked a similar question, in which they used the phrase “when Ellen has been awake for exactly two turns."

I’m predicting that most scenes in my projects would more likely be the result of the player taking an action.

This is akin to what I’ve been trying: “Smugglers Fleeing begins after the player has looked into the keyhole.” In fact what I was hoping to do was “…after the player has looked into the keyhole for the third time.”

I worked around it by using this:

Smuggler Jake can be relaxed or fleeing. Smugglers Fleeing begins when smuggler Jake is fleeing. After the player has looked into the keyhole for the third time, now Smuggler Jake is fleeing.
Is that the most straightforward approach?

This next one really is a question though, as I’ve struggled against the syntax for weeks. How do you match up table entries with specific objects in the game? Eg:

[code]“Treasures”

A treasure is a kind of thing. A treasure has a number called treasure_points.

Table 1.0 - Treasure Scores
Treasure Name Treasure Reward
“Gold nugget” 10
“Diamonds” 20
“Silver bars” 5
“Jewelry” 5
“Rare coins” 10
“Emerald” 25
“Platinum Pyramid” 30
“Pirate’s Treasure” 30

Brick Building is a room. “You are inside a building, a well house for a large spring.”

Elsewhere is a room. “This is just a treasure storage area.” A Gold nugget, Diamonds, Silver Bars, Jewelry, Rare Coins, Emerald, Platinum Pyramid and Pirate’s Treasure are in Elsewhere. The Gold nugget, Diamonds, Silver Bars, Jewelry, Rare Coins, Emerald, Platinum Pyramid and Pirate’s Treasure are treasures.

When play begins:
repeat with T running through treasures:
if there is a Treasure Name corresponding to the printed name of T in the Table of Treasure Scores:
let N be the Treasure Reward corresponding to the printed name of T in the Table of Treasure Scores;
now the treasure_points of T is N.[/code]

I know it’s not working because T is an object name while the printed name of objects is text. How to resolve this is unclear. What’s the correct syntax?

In fact it would be good if I could go as far as to create objects using a table, and better still if I can assign their rooms via table. Can either of these things be done?

The syntax for that would be:

Smugglers fleeing begins when we have examined the keyhole for the third time.

Only, that won’t work as expected. Since the scene changing rules are considered twice every turn, the game will count “us” as having examined the keyhole twice for each turn the keyhole is examined.
I suppose this should be considered a bug, but I don’t think it has been reported yet. EDIT: Well, now I’ve reported it.

There are several ways to handle your table. The basic problem is that you put strings in the table rather than the objects themselves. Matching strings is always harder than matching object references or values.

When play begins:
	repeat with T running through treasures:
		let N be the Treasure Reward corresponding to a Treasure Name of T in the Table of Treasure Scores;
		now the treasure_points of T is N.

Or:

When play begins:
	repeat with T running through treasures:
		if T is a Treasure Name listed in the Table of Treasure Scores:
			now the treasure_points of T is the Treasure Reward entry.

Or:

When play begins:
	repeat through the Table of Treasure Scores:
		now the treasure_points of Treasure Name entry is Treasure Reward entry.

Or you could skip the “when play begins” rule entirely, and define the objects straight from the table:

A treasure is a kind of thing.  A treasure has a number called treasure_points.

Some treasures in the Kitchen are defined by the Table of Treasure Scores.

Table 1.0 - Treasure Scores
treasure	treasure_points
Gold nugget	10
Diamonds	20
Silver bars	5
Jewelry	5
Rare coins	10
Emerald	25
Platinum Pyramid	30
Pirate's Treasure	30

One more, just for fun. Instead of defining a property and filling it in from the table, you could just use the table directly in play:

A treasure is a kind of thing.

To decide what number is treasure_points of (T - treasure):
	let N be the Treasure Reward corresponding to a Treasure Name of T in the Table of Treasure Scores;
	decide on N.

(Note we do not say “A treasure has a number called treasure_points” in this example.)

Using a “decide” phrase like this is a little less flexible – if you wanted to change a treasure’s score, you’d have to change the table instead of writing “now the treasure_points of the emerald is 26”. But if you’re not changing values, it works just as well.

Thanks for suggesting those Zarf, but are you sure the syntax is correct? I haven’t been able to get any of them to compile. I receive various error messages, all of them complaining that Inform can’t recognise the sentence structures. I’ve checked indentations, looked at the colon and comma arrangements. I’ve modified the names slightly, including putting underscores “_” between the names in case Inform was misunderstanding the use of “Treasure.” I even downloaded and reinstalled Inform to ensure the compiler was up to date.

Can you tell me more about “The basic problem is that you put strings in the table rather than the objects themselves.” I recognised this as the problem when I first was trying to design the code and before I posted, however I haven’t been able to figure out the correct approach myself. I’ve tried each of your suggestions with and then without quotes around the table entries and still they wouldn’t compile.

I compiled each of them and tested before posting. (I know that if post untested code, it’s just as likely to be wrong as the next guy’s untested code, so I try to be obsessive about it…)

Not sure what else to say. If you post a specific example, and the error message, I can tell you why it isn’t working.

Inform’s ability to compare literal strings is confusing at best. (There are three different ways to customize the name of an object, to begin with; plus you could use string substitutions to vary the displayed text. All of that makes it hard to say what object is identified with the string “Gold nugget”. Then there’s bug inform7.com/mantis/view.php?id=459 , which can give you the wrong answer even if you write correct code.)

Comparing object references or values is always reliable.

Just in case, here is my entire test file:


"Test Case" by Andrew Plotkin.

The Kitchen is a room. "Kitcheny."

A treasure is a kind of thing. A treasure has a number called treasure_points.

The Gold nugget, Diamonds, Silver Bars, Jewelry, Rare Coins, Emerald,  Platinum Pyramid and Pirate's Treasure are treasures in the Kitchen.

Table 1.0 - Treasure Scores
Treasure Name	Treasure Reward
Gold nugget	10
Diamonds	20
Silver bars	5
Jewelry	5
Rare coins	10
Emerald	25
Platinum Pyramid	30
Pirate's Treasure	30

Check examining a treasure:
	instead say "[The noun] is worth [treasure_points of noun]."

When play begins:
	repeat through the Table of Treasure Scores:
		now the treasure_points of Treasure Name entry is Treasure Reward entry.

Hi Zarf,

I started over again. This time the first three worked, and I could hear Inform7 laughing at me. Then when I reached number four I thought “Hang on, did I actually test number three properly?” So I re-did number three and got it wrong. So I went right back to the start again and managed to get that one wrong also.

At least this confirms one thing: the mistake(s) are at my end. I think I’m slipping up with my indentation, or maybe a punctuation character somewhere.

Most of the compilaiton messages I received were concerning the structure of the loops and ‘if’ statements.

Eventually I did succeed in getting each of the first three, and then number five, to work perfectly.

With number four (definining the treasures directly from the table), it took me a while to realise that the phrase “Some treasures in the Kitchen are defined by the Table of Treasure Scores.” has to come just after the creation of the room. Then it worked fine.

Early days. Eventually this will all be second nature to me.

All good now. Thanks for your help Zarf, and especially your patience!

Been experimenting with defining objects via table. I performed a text search of “are defined by the Table” which took me to Chapter 15.16 of the manual “Defining things with tables.” I’d actually read that during my lunch at work a couple of weeks ago and it just hadn’t clicked in my 2-bit brain. However there’s not much more information on using tables in this manner. I’m particularly interested in knowing if you can pre-set the locations of things defined by table, including divvying them up as the possessions of other characters.

I’ve been endeavouring to figure this out (while it may not appear so, I do try to learn by my own effort. I’m just not very good at learning).

My attempt here was to use a table column called “Location” to assign the things to their rooms (currently only 2 rooms exist here). It seemed a reasonable guess, given that “Location” is one of the properties of things as revealed by the Showme command.

Eg:

Showme Nugget
Gold nugget - treasure
location: in Building
singular-named, proper-named; unlit, inedible, portable
printed name: “Gold nugget”
printed plural name: “treasures”
indefinite article: none
description: “Sparkly”
initial appearance: none
treasure_points: 10
Location: Building
treasure_description: “Sparkly”

[code]“Treasures”

Building is a room. “You are inside a building, a well house for a large spring…”

End of road is a room. “You are standing at the end of a road before a small brick building.” End of road is west of Building. End of road is outside from Building.

The player is in building. A man called Smith is in building.
Persuasion rule for asking someone to try doing something: persuasion succeeds.

A treasure is a kind of thing. A treasure has a number called treasure_points.

Some treasures in the Building are defined by the Table of Treasure Scores. The description of a treasure is “[treasure_description]”.

Table 1.0 - Treasure Scores
treasure Location treasure_points treasure_description
Gold nugget Building 10 “Sparkly”
Diamonds Building 20 “Glittery”
Silver bars Building 5 “Smooth and silvery”
Jewelry Building 5 “Assorted gems and trinkets”
Rare coins Building 10 “Varied”
Emerald Building 25 “The size of a plover’s eg”
Platinum Pyramid Building 30 “30 inches on a side”
Pirate’s Treasure Building 30 “Nondescript”

Check examining a treasure:
instead say “The [The noun], [description of the noun] is worth [treasure_points of noun].”[/code]
It appears to work OK, but the player is unable to move. This is the result if you try going to the adjacent location:

[code]>out

*** Run-time problem P10: Since yourself is not allowed the property “location”, it is against the rules to try to use it.

[** Programming error: tried to “move” yourself to nothing **]
You get out of Building.[/code]
(NOTE: Although it says so, you actually remain in the building).

[code]>w

*** Run-time problem P10: Since yourself is not allowed the property “location”, it is against the rules to try to use it.

You’ll have to get out of Building first.[/code]

It also affects the NPC:

[code]>smith, w

*** Run-time problem P10: Since Smith is not allowed the property “location”, it is against the rules to try to use it.

Smith is unable to do that.[/code]

Interesting. Any idea why the table is messing up the player & NPC location properties?

Looks like a namespace clash between the built-in location properties and the “location” column, which is getting turned into a property of treasures. (When you define the treasures by the table, it’s as though you had said “A treasure has a room called the location,” I think.) Try changing the name of the location column to “starting place.”

…and anyway, as you may have noticed, your code isn’t distributing treasures to the rooms you want anyway. Once you’ve changed the column name to “starting place” you can do this:

When play begins: repeat with item running through treasures: move item to the starting place of item.

The main issue is that you can’t set location directly in your code, even though “location” is something that shows up in the showme’s. The location is the room that the thing is in (or the container/supporter holding it); when you ask for the location of something, Inform looks to see where it is, and tells you. So when you tried to set it directly, Inform thought you were creating a new property called “location” and got all confused.

Thanks Matt W.

I hadn’t realised that defining things via table creates whole new properties.

That code sure solves that problem thanks. :slight_smile: Having seen it work I wanted to experiment a bit more, but I’m not having one of my good days healthwise :frowning:.

Just to prove to everyone that I do sometimes solve problems on my own, I completed my rudimentary test of using tables to create a gnome character who moves the treasures outside the building into the building by following instrucitons from a table.

[code]“Treasures”

Building is a room. “You are inside a building, a well house for a large spring…”

End of road is a room. “You are standing at the end of a road before a small brick building.” End of road is west of Building. End of road is outside from Building.

The player is in building. The Gnome is a man in building. The Gnome has a number called G_Seq. The G_Seq of The Gnome is 1.
Persuasion rule for asking someone to try doing something: persuasion succeeds.

A treasure is a kind of thing. A treasure has a number called treasure_points.

Some treasures in the Building are defined by the Table of Treasure Scores. The description of a treasure is “[treasure_description]”.

Table 1.0 - Treasure Scores
Treasure Treasure_start treasure_points treasure_description
Gold nugget End of road 10 “Sparkly”
Diamonds Building 20 “Glittery”
Silver bars End of road 5 “Smooth and silvery”
Jewelry Building 5 “Assorted gems and trinkets”
Rare coins End of road 10 “Varied”
Emerald Building 25 “The size of a plover’s eg”
Platinum Pyramid End of road 30 “30 inches on a side”
Pirate’s Treasure Building 30 “Nondescript”

Check examining a treasure:
instead say “The [The noun], [description of the noun] is worth [treasure_points of noun].”

When play begins:
repeat with item running through treasures:
move item to the Treasure_start of item.

Table 2.0 - The Gnome’s actions
Gnome_moves Gnome_takes Gnome_drops
End of road – --
– Gold Nugget –
Building – --
– -- Gold Nugget
End of road – --
– Silver bars –
Building – --
– -- Silver Bars
End of road – --
– Rare coins –
Building – --
– -- Rare coins
End of road – --
– Platinum Pyramid –
Building – --
– -- Platinum Pyramid

Every turn:
let N be the G_Seq of The Gnome;
if N minus one is less than the number of rows in the Table of The Gnome’s actions:
choose row N in the Table of The Gnome’s actions;
if there is a Gnome_moves in row N of the Table of The Gnome’s actions:
let last space be the location of The Gnome;
if The Gnome can be seen by the player, say “The Gnome heads to [the Gnome_moves entry].”;
move The Gnome to the Gnome_moves entry;
if The Gnome can be seen by the player, say “The Gnome arrives from the [the last space].”;
if there is a Gnome_takes in row N of the Table of The Gnome’s actions:
try The Gnome taking the Gnome_takes entry;
if there is a Gnome_drops in row N of the Table of The Gnome’s actions:
try The Gnome dropping the Gnome_drops entry;
say “The Gnome is at turn sequence [G_Seq of The Gnome]”;
increase the G_Seq of The Gnome by 1.
[/code]

Though what you see is all you get I became interested in what it would be like to have friendly helper characters in Colossal Cave. Has anyone re-created any Inform7 versions of Colossal Cave with the source code provided? Failing that, if I do need to create the whole thing from scratch (time cosuming but not that difficult) does anyone know of any comprehensive maps of the game?

There’s this thread: I7 port of Crowther's Colossal Cave looking for testers

I don’t know what happened to it, though.

Oh, I’m still around, and my latest unreleased version fixes a few bugs people have reported in the meantime. My decision to hold off on a release until after the next version of I7 seemed like a better idea 2 years ago, though…

LOL! :laughing:

Life has it’s twisty little turns, all unalike. Does it not? :wink:

(To all)
Anyway, I decided to make it a project of my own and it’s going well. This one has proved far less challenging than my earlier project and is proving a useful learning exercise. Best of all it doesn’t matter if my health problems take me a way from the project for a few days because it’s so simple that I can resume where I left off without having to remember what I was up to.

I’m up to creating the steel grate, and Inform is behaving oddly.

This is what should happen:

This is what’s happening instead:

(Gah! No kidding Inform?)

Tried this, it didn’t help:

Does the player mean unlocking the keys with the keys: it is very unlikely. Does the player mean unlocking the steel grate with the keys: it is very likely.

I also tried:

Does the player mean unlocking the steel grate: it is very likely.

No good - compilation error.

Suggestions?

I think you need to use a “for supplying a missing noun” rule here. That’s what I did, anyway.

No, that has no effect on the unlocking action. (With the standard grammar.)

See discussion in this thread: Unlocking Issue: Handcuffs?

You should try:

Does the player mean unlocking the steel grate with: it is very likely.

However, my advice in this situation is always to not worry about it. The parser tends to pick objects arbitrarily when there’s a single portable object in scope, but nearly always the player will have more than one object lying around, so you won’t get that response anyhow.

Thanks Zarf, that worked a treat!

I’m going to have to read that thread a few times though to understand it. Inform is a highly capable language… also highly complex for those like myself who get mentally stuck on little details. :blush:

Latest problem:
In the Colossal Cave Adventure there were steps linking the rooms “Top of Small Pit” and “Hall of Mists”, and which were part of a puzzle involving a large gold nugget. The nugget was too heavy to lift up the steps.

You had to carry the nugget to the Y2 room and use the magic word “Plugh” to return to the building. An alternative solution was to wander around until the pirate stole the nugget, then retrieve it from his hiding spot and descend from the maze into the Splendid Chamber.

(In fact if you succeeded and then went back to the Top of Small Pit and then tried going down the steps while carrying it you would suffer a fatal fall.)

The description of the stairs themselves would be removed from the room descriptions whenever the nugget was in the player’s inventory. It took me a bit of fiddling around, but I eventually figured out how to control that (I do sometimes succeed in solving my own problems). The below code works, I’m just looking for opinions as to whether it’s the most straightforward approach?

[code]A room called Top of Small Pit is west of Splendid Chamber. “At your feet is a small pit breathing traces of white mist. An east passage ends here except for a small crack leading on.[spiel for rough stone steps]”.

The rough stone steps is down from Top of Small Pit and up from Hall of Mists. The rough stone steps is an open door. The rough stone steps is not openable. The rough stone steps is scenery.

To say spiel for rough stone steps:
if the player does not carry the large gold nugget:
say "[Line break][Line break]Rough stone steps lead [if the player is in Top of Small Pit]down the pit[otherwise]up the dome[end if]. "; [Note, the space after the full stop is to prevent a superfluous line break]
otherwise:
stop the action.

Hall of Mists is a room. “You are at one end of a vast hall stretching forward out of sight to the west. There are openings to either side. Nearby, a wide stone staircase leads downward. The hall is filled with wisps of white mist swaying to and fro almost as if alive. A cold wind blows up the staircase. There is a passage at the top of a dome behind you.[spiel for rough stone steps]”.[/code]