I’m trying to implement a basic choice-based conversation system. Here’s how it works:
A person has a table-name called dialog. A person has some text called initial greeting. The initial greeting of a person is usually "What?"
Now to use it:
Dirk is a man in the Inn with the description "A sturdily-built man with hair already graying."
The dialog of Dirk is the Table of Dirk's Conversation.
The initial greeting of Dirk is "What's new, traveller?"
Table of Dirk's Conversation
id phrase response unlocks availability
"buyBeer" "Can I buy a beer?" "Are you 18 yet?" "giveID" true
"giveID" "Here's my ID." "Fine. Here you go." -- false
"chatter" "What's new around here?" "Nothing much." -- true
"gossip" "So... any gossip?" "My lips are sealed." "bribeGossip" true
"bribeGossip" "[bracket]Hand over $20[close bracket]" "Well, I hear there's an adventurer in town..." -- false
All is well and good so far. Now, let’s implement a way to acess these dialog tables:
Table of Current Dialog
id phrase response unlocks
with 16 blank rows.
Understand "talk to [someone]" as talking to. Talking to is an action applying to one thing.
The available option is a truth state that varies.
Carry out talking to:
say "'[initial greeting of the noun]'";
repeat with N running from 1 to the number of rows in the dialog of the noun: [we have to iterate manually so we can select blank rows in a different table]
now the available option is availability in row N of the dialog of the noun;
if the available option is true:
choose a blank row in the table of current dialog;
now id entry is the id entry of the noun;
now phrase entry is the phrase entry of the noun;
now response entry is the response entry of the noun;
now unlocks entry is the unlocks entry of the noun;
repeat through the table of current dialog:
say "- [phrase entry] [line break]".
But Inform 7 doesn’t like my phrasing of now XXX entry is the XXX entry of the noun
.
All in all, this feels like a deeply clunky solution. What’s the best way to go about this?
The reason for the error is that you’re checking for “of the noun
” in these lines:
now id entry is the id entry of the noun;
now phrase entry is the phrase entry of the noun;
now response entry is the response entry of the noun;
now unlocks entry is the unlocks entry of the noun;
But at that point, we’re in the context of Carry out talking to
, which means that the noun
is Dirk himself, not his dialog table.
To fix this, the following seems to work:
now id entry is the id in row N of the dialog of the noun;
now phrase entry is the phrase in row N of the dialog of the noun;
now response entry is the response in row N of the dialog of the noun;
now unlocks entry is "blank";
if there is an unlocks in row N of the dialog of the noun:
now unlocks entry is the unlocks in row N of the dialog of the noun;
Note that we also simply say “the id in row N
” etc., not “the id entry in row N
”, and that we have to take special care because of the blank entries (in the unlocks column), otherwise it can lead to runtime errors.
For some conversation-related table handling code, you could also take a look at the “Sweeney” example in chapter “7.8 Saying Complicated Things” in the Recipe Book.
By the way, I’m not completely sure whether you really need to copy the table. Depends of course on the details of the system you’re planning to implement.
In general, you might also want to take a look at some extensions which make it fairly easy to have menu-based conversations: There are Michael Martin’s Reactable Quips and Quip-Based Conversation, and there’s also the excellent “Hybrid Choices” by AW Freyr.
4 Likes
I was also able to get this to work by making basically the same changes as @StJohnLimbo (although I cheated and just filled in your blank rows with empty text), but I concur that copying the table into another “working table” seems overly clunky and that you should at least look at the example and extensions mentioned to get some ideas or perhaps avoid reinventing the wheel in the first place.
(Although I realize that some people like reinventing the wheel as an exercise to learn the language, which of course is perfectly fine.)
1 Like
I wanted to do this, but I couldn’t find any good documentation on them. That’s one thing that, as a programmer, irritates me somewhat about Inform: documentation is often sparse or unusually formatted (from my perspective).
Where can I find some documentation for Michael Martin’s extensions? I’d much rather not try to puzzle out what the code does.
This works for now, though. Thanks for that
The documentation is included in the extension files themselves. After the actual I7 source code part, there’s a second part which starts with ---- DOCUMENTATION ----
.
If you install an extension in I7, its documentation (including examples) will be available from the extensions tab.
1 Like
Excellent! Thank you again.
1 Like