action includes/matching

Hello!

I’m brand new to Inform and have run into some confusion about storing and testing actions.

I’m trying to create a little game where the character can ‘remember’ things that happen and recall them later. Basically, I want to turn the last action of other actors (or the player) into a list of topics, some of which will have a more detailed description. I’ve been using camera and video examples as inspiration, but have run into trouble when I try to turn an action into a description.

The basic idea is here (code probably won’t compile as written):

[code]The kitchen is a room. Richard is a man in the kitchen. The chicken hat is a wearable thing in the kitchen.

[creating a memory databank]
Table of Memories
index memory-subject
1 “Your first day of school”
2 “Getting breakfast with Richard”
3 “Sarah waving goodbye”
with 27 blank rows.

Memory is a part of ever person.
Instead of examining memory:
say “You remember: [paragraph break]”;
repeat through the Table of Memories:
say “memory-subject entry”.

Remembering is an action applying to one visible thing.
Understand “remember [something]” as remembering.

Check remembering:
if the noun is the player, say “How could you forget?” instead.

Check remembering:
if the number of blank rows in the Table of Memories is less than 1:
say “You get a headache as your brain struggles to retain all the things that you’ve seen.”

[capturing the last action]
Table of Richard Action
recorded action
Richard eating

After Richard doing something:
blank out the whole of the Table of Richard Action;
choose a blank row in the Table of Richard Action;
now the recorded action entry is the current action;

[committing the last thing you’ve seen to memory - this is where it all goes kablooey]
Carry out remembering:
let subject be the noun;
let site be the location;
choose a blank row in Table of Memories;
let N be the number of filled rows in the Table of Memories + 1;
now index entry is N;
if the subject is Richard:
let RA be recorded action entry in row 1 of the Table of Richard Action;
repeating through the Table of Described Richard Memories:
if RA includes topic entry:
now memory-subject entry is “[description entry]”;
else:
now memory-subject entry is “[The subject] in [site]”.

Table of Described Richard Memories
topic description
eating “Richard lazily eating with his mouth open”
going “Richard rushing out the door, late for class”
wearing chicken hat “Richard goofing off while wearing that ridiculous chicken hat”[/code]

Part of the issue seems to be storing an action and then texting it against text/a topic. Inform doesn’t like the value differences, but I can’t figure out how to convert them.

I know the last action storing method is stupid, but I couldn’t get stored actions to work for some reason.

I’m really enjoying the language overall, but a lot of the more advanced concepts (and even some of the simpler ones) are really eluding me.

Thanks for any advice!

This is a pretty ambitious problem for someone new to Inform. Feel free to ask additional questions about any of the following.

Your example reflects a confusion about data types.

A topic is a description of a pattern of input to be understood by the parser. Internally, it’s a routine that analyzes some input and determines if the input matches the topic. “remember [something]” is an example of a topic, as is just plain “hello”. So, you can’t match a topic against an action, because an action isn’t input (it’s generated from input after the input has been parsed successfully).

There are at least three different action-related types: action names, (stored) actions, and described actions. Action names are just the name of an action (“the eating action”). (Stored) actions are fully specified actions (actor, action name, noun, second noun) (e.g., “Richard eating the apple”). If no actor is given, the player is assumed, and noun and second noun aren’t required for all actions. Described actions are actions that are not fully constrained and describe a set of possible actions (e.g., “eating something”, “smelling a locked door”).

Internally, action names are simple I6 action constants like ##Eat; stored actions are data structures containing the various fields for actor, action, noun, second noun; and described actions are code that analyzes a specific action against a description of a set of actions and determines whether it is a member of the set.

The “actions” in the (misnamed) topic column of your action descriptions table are a combination of described actions (eating) and actions (wearing the chicken hat). All of the values in a table column need to be of the same type, so the compiler is unhappy with that column. The issue is compounded by a bug (inform7.com/mantis/view.php?id=1844) where, instead of the I7 compiler generating an error when a described action is placed into a table, the compiler instead produces broken I6 code – it places the code associated with the described action into an array where it’s not allowed to be. If you only wanted to match fully specified actions, the problem would be easier, but you want to match action descriptions as well.

I took a crack at fixing and extending your program.

My solution was to decompose the actions/action descriptions into an action name, a noun, and a second noun and give each element of the action its own table column. See §12.20. Stored actions. I also generalized the code a bit so that all characters have memories and all characters can have detailed action descriptions. There are still several open issues; see the comments in the code.

[rant][code]
“All Alone in the Mooooonlight”

Section 1 - Memory

A memory is a kind of thing. It is part of every person.
A memory has a table name called the recollections.

Instead of examining a memory when the recollections of the noun is empty, say “[The holder of the noun] [don’t] remember anything.”

To remember is a verb.
Instead of examining a memory:
say “[The holder of the noun] [remember]:[line break]”;
repeat through the recollections of the noun:
say " [description entry][line break]"

Does the player mean examining a memory that is part of the player: it is likely.

Section 2 - Player’s Memories

[creating a memory databank]
Table of Player’s Memories
description
“Your first day of school”
“Getting breakfast with Richard”
“Sarah waving goodbye”
with 27 blank rows.

When play begins:
let M be a random memory that is part of the player;
now the recollections of M is the Table of Player’s Memories.

Section 3 - Richard’s Memories

Table of Richard’s Memories
description
with 30 blank rows.

When play begins:
let M be a random memory that is part of Richard;
now the recollections of M is the Table of Richard’s Memories.

Section 4 - Action Descriptions

A person has a table name called the action descriptions.

Section 5 - Richard’s Action Descriptions

[We can’t mix actions and described actions in the same table column, and we can’t put described actions in a table at all.

So… we’re going to break the action into its component parts and give each its own column.

We allow overlapping action descriptions. We’ll match the most specific one.]

Table of Richard’s Action Descriptions
action noun second (object) description
eating action – – “Richard lazily eating [the noun part of the recorded action of Richard] with his mouth open”
eating action apple – “Richard eating an apple”
going action – – “Richard rushing out the door, late for class”
wearing action chicken hat – “Richard goofing off while wearing that ridiculous chicken hat”
giving it to action chicken hat – “Richard lending his hat to [the second noun part of the recorded action of Richard]”
giving it to action – yourself “Richard giving [the noun part of the recorded action of Richard] to you”
giving it to action apple yourself “Richard tossing an apple to you”

The action descriptions of Richard is the Table of Richard’s Action Descriptions.

Section 6 - Player’s Action Descriptions

Table of Player’s Action Descriptions
action noun second (object) description
remembering action Richard – “you remembering Richard (so meta)”
jumping action – – “you jumping around”
remembering action – – “you remembering [the noun part of the recorded action of the player]”

The action descriptions of the player is the Table of Player’s Action Descriptions.

Section 7 - Recording Most Recent NPC Action

[Don’t see the need for a table, since code’s only using the most recent action.]

[This could allow characters to remember things that didn’t happen in their presence.

For full generality, we’d want this info stored in the viewer rather than the actor and for it to be parameterized by the actor. So, each character would recall the last thing that they saw each other character do.

In this game, though, Richard only acts when prompted by the player, so the player witnesses everything that he does.]

A person has an action called the recorded action.

After an actor doing something:
now the recorded action of the actor is the current action;
continue the action.

Section 8 - Forgetting

Forgetting is an action applying to nothing.
Understand “forget” as forgetting.

Carry out an actor forgetting:
let M be a random memory that is part of the actor;
blank out the whole of the recollections of M.

To forget is a verb.
Report an actor forgetting:
say “[The actor] [forget] everything.”

Section 9 - Remembering

[Memorize seems like a better name for this, since it’s commiting something to memory rather than recalling something previously committed to memory.]

[We can remember the same thing multiple times. Could give people a “recorded action remembered” flag, but this too ought to be per-actor. For now, we just allow it.]

[We can’t remember things that have gone out of play, like the apple after it’s been eaten.]

Remembering is an action applying to one visible thing.
Understand “remember [something]” or “recall [something]” as remembering.
[Allow us to remember people when they’re not present. In other games, this could allow us to remember people we’ve never met.]
Understand “remember [any person]” or “recall [any person]” as remembering.

The remembering action has a text called the remembered action description.

Check an actor remembering the actor (this is the can’t forget yourself rule):
instead say “How could [regarding the actor][those in the nominative] forget?”

Check an actor remembering when the recollections of a random memory that is part of the actor is full (this is the can’t remember with a full memory rule):
instead say “[The actor] [get] a headache as [their] brain struggles to retain all the things that [they]['ve] seen.”

[This is a little complex because we want to allow more specific action descriptions (eating the apple) to win out over more general action descriptions (eating) regardless of their order in the table.]
To decide which text is the recorded action description for (P - person):
[1 point for action match, 1 point for explicit second noun match, 2 points for explicit noun match]
[0 = no match, 1 = action match, 2 = action + second noun match, 3 = action + noun match, 4 = action + noun + second noun match]
[highest score wins]
let the best confidence be 0;
let the best match be the substituted form of “[the recorded action of P]”;
repeat through the action descriptions of P:
if the action name part of the recorded action of P is not the action entry, next;
let the current confidence be 1;
if there is a noun entry:
if the noun part of the recorded action of P is not the noun entry, next;
now the current confidence is the current confidence + 2;
if there is a second entry:
if the second noun part of the recorded action of P is not the second entry, next;
now the current confidence is the current confidence + 1;
if the current confidence > the best confidence:
now the best confidence is the current confidence;
now the best match is the substituted form of the description entry;
decide on the best match.

Carry out an actor remembering something:
let M be a random memory that is part of the actor;
choose a blank row in the recollections of M;
if the noun is a person, now the remembered action description is the recorded action description for the noun;
if the remembered action description is empty, now the remembered action description is the substituted form of “[the noun] in the [location of the noun]”;
now the description entry is the remembered action description.

Report an actor remembering:
say “[The actor] [remember] [the remembered action description].”

Section 10 - NPC Actions

Persuasion rule for asking someone to try doing something: persuasion succeeds.

The block giving rule is not listed in the check giving it to rules.

Unsuccessful attempt by an actor remembering when the reason the action failed is the can’t forget yourself rule: stop.

Unsuccessful attempt by an actor remembering when the reason the action failed is the can’t remember with a full memory rule: stop.

Section 11 - The Kitchen

Kitchen is a room.
Richard is a man in the Kitchen.
The chicken hat is a wearable thing in the Kitchen.
The apple is an edible thing in the Kitchen.
The orange is an edible thing in the Kitchen.
The jacket is a wearable thing in the Kitchen.

The Hallway is south of the Kitchen.

Section 12 - Tests

Test me with “x my memory / x richard’s memory / remember me / richard, remember richard / richard, give apple to me / remember richard / x memory / richard, wear chicken hat / remember richard / x memory / forget / x memory / give apple to richard / richard, eat apple / remember richard / richard, eat orange / remember richard / richard, remember me / x memory / x richard’s memory / jump / richard, remember me / remember jacket / richard, remember me / x richard’s memory / richard, forget / x richard’s memory / richard, give jacket to me / remember richard / richard, s / remember richard / x memory”.
[/code][/rant]
An alternate approach is to abandon the idea of matching action descriptions using a table and to instead use a rulebook. This allows us to take advantage of Inform’s built-in rule ordering where more specific rules run prior to more general rules. See chapter 19: Rulebooks, especially §19.13. Rulebooks producing values.

Here’s an implementation using that approach. See sections 4-6, and 8 for the significant changes relative to the previous table-based version.

[rant][code]
“All Alone in the Mooooonlight”

Section 1 - Memory

A memory is a kind of thing. It is part of every person.
A memory has a table name called the recollections.

Instead of examining a memory when the recollections of the noun is empty, say “[The holder of the noun] [don’t] remember anything.”

To remember is a verb.
Instead of examining a memory:
say “[The holder of the noun] [remember]:[line break]”;
repeat through the recollections of the noun:
say " [description entry][line break]"

Does the player mean examining a memory that is part of the player: it is likely.

Section 2 - Player’s Memories

[creating a memory databank]
Table of Player’s Memories
description
“Your first day of school”
“Getting breakfast with Richard”
“Sarah waving goodbye”
with 27 blank rows.

When play begins:
let M be a random memory that is part of the player;
now the recollections of M is the Table of Player’s Memories.

Section 3 - Richard’s Memories

Table of Richard’s Memories
description
with 30 blank rows.

When play begins:
let M be a random memory that is part of Richard;
now the recollections of M is the Table of Richard’s Memories.

Section 4 - Action Descriptions

[We record a description of a person’s most recent action in their recorded action description property that will be used by the remembering action.

This could allow characters to remember things that didn’t happen in their presence.

For full generality, we’d want this info stored in the viewer rather than the actor and for it to be parameterized by the actor. So, each character would recall the last thing that they saw each other character do.

In this game, though, Richard only acts when prompted by the player, so the player witnesses everything that he does.]

[In this version of the program, we create our own action-based rulebook to take advantage of Inform’s rule ordering, where more specific rules are applied prior to more general rules. This allows descriptions of more specific actions to take precedence. In the other table-based version of the program, we did this prioritization manually.

We use a separate rulebook, called from an after rule, so that we can return early from a specific rule without running more general rules but also without disrupting action processing – that is, so that additional after and report rules will still run.]

A person has text called the recorded action description.

Action description rules is a rulebook producing a text.

After an actor doing something:
now the recorded action description of the actor is the text produced by the action description rules;
continue the action.

Action description for an actor doing something:
rule succeeds with result the substituted form of “[the current action]”.

Section 5 - Richard’s Action Descriptions

Action description for Richard eating something:
rule succeeds with result the substituted form of “Richard lazily eating [the noun] with his mouth open”.

Action description for Richard eating the apple:
rule succeeds with result “Richard eating an apple”.

Action description for Richard going somewhere:
rule succeeds with result “Richard rushing out the door, late for class”.

Action description for Richard wearing the chicken hat:
rule succeeds with result “Richard goofing off while wearing that ridiculous chicken hat”.

Action description for Richard giving the chicken hat to someone:
rule succeeds with result the substituted form of “Richard lending his hat to [the second noun]”.

Action description for Richard giving something to the player:
rule succeeds with result the substituted form of “Richard giving [the noun] to you”.

Action description for Richard giving the apple to the player:
rule succeeds with result “Richard tossing an apple to you”.

Section 6 - Player’s Action Descriptions

Action description for remembering Richard:
rule succeeds with result “you remembering Richard (so meta)”.

Action description for jumping:
rule succeeds with result “you jumping around”.

Action description for remembering something:
rule succeeds with result the substituted form of “you remembering [the noun]”.

Section 7 - Forgetting

Forgetting is an action applying to nothing.
Understand “forget” as forgetting.

Carry out an actor forgetting:
let M be a random memory that is part of the actor;
blank out the whole of the recollections of M.

To forget is a verb.
Report an actor forgetting:
say “[The actor] [forget] everything.”

Section 8 - Remembering

[Memorize seems like a better name for this, since it’s commiting something to memory rather than recalling something previously committed to memory.]

[We can remember the same thing multiple times. Could give people a “recorded action remembered” flag, but this too ought to be per-actor. For now, we just allow it.]

[We can’t remember things that have gone out of play, like the apple after it’s been eaten.]

Remembering is an action applying to one visible thing.
Understand “remember [something]” or “recall [something]” as remembering.
[Allow us to remember people when they’re not present. In other games, this could allow us to remember people we’ve never met.]
Understand “remember [any person]” or “recall [any person]” as remembering.

The remembering action has a text called the remembered action description.

Check an actor remembering the actor (this is the can’t forget yourself rule):
instead say “How could [regarding the actor][those in the nominative] forget?”

Check an actor remembering when the recollections of a random memory that is part of the actor is full (this is the can’t remember with a full memory rule):
instead say “[The actor] [get] a headache as [their] brain struggles to retain all the things that [they]['ve] seen.”

Carry out an actor remembering something:
let M be a random memory that is part of the actor;
choose a blank row in the recollections of M;
if the noun is a person, now the remembered action description is the recorded action description of the noun;
if the remembered action description is empty, now the remembered action description is the substituted form of “[the noun] in the [location of the noun]”;
now the description entry is the remembered action description.

Report an actor remembering:
say “[The actor] [remember] [the remembered action description].”

Section 9 - NPC Actions

Persuasion rule for asking someone to try doing something: persuasion succeeds.

The block giving rule is not listed in the check giving it to rules.

Unsuccessful attempt by an actor remembering when the reason the action failed is the can’t forget yourself rule: stop.

Unsuccessful attempt by an actor remembering when the reason the action failed is the can’t remember with a full memory rule: stop.

Section 10 - The Kitchen

Kitchen is a room.
Richard is a man in the Kitchen.
The chicken hat is a wearable thing in the Kitchen.
The apple is an edible thing in the Kitchen.
The orange is an edible thing in the Kitchen.
The jacket is a wearable thing in the Kitchen.

The Hallway is south of the Kitchen.

Section 11 - Tests

Test me with “x my memory / x richard’s memory / remember me / richard, remember richard / richard, give apple to me / remember richard / x memory / richard, wear chicken hat / remember richard / x memory / forget / x memory / give apple to richard / richard, eat apple / remember richard / richard, eat orange / remember richard / richard, remember me / x memory / x richard’s memory / jump / richard, remember me / remember jacket / richard, remember me / x richard’s memory / richard, forget / x richard’s memory / richard, give jacket to me / remember richard / richard, s / remember richard / x memory”.
[/code][/rant]

Whoa! This was incredibly helpful! Thank you so much!

I had a feeling I was swimming out into deeper waters than I meant to for my first game. I’ve been trying to cram a lot in, but there’s definitely a lot (like the interplay of data types) that completely goes over my head. Seeing the not only the solution, but the thinking behind it is really instructive.

Much appreciated!