Eleas: Iâm only seeing your post on preview, but you canât quite do that because when you type âask about swordsâ what actually happens is that it executes the action of asking about the first sword, and then the action of asking about the second sword, and so on. So you have to check the multiple object listâwhich in fact can be accessed in the middle of the action machinery, even with a plain old â[things]â tokenâwhen you do the first action, and then cut off the remaining actions before they get started. Which is what The Left Hand of Autumn does, and what the below code should do more generally!
So I thought I would try to wrap things up in a general solution. Hereâs a start on what might be an extension for handling acting on groups, with a reimplementation of the code example The Left Hand of Autumn. Now if you want examining to work on groups, and you want to write a special rule for when the objects youâre examining happen to be the objects in the fruit list, you can write:
[code]Examining is groupable action. Understand âexamine [things]â as examining.
An action on groups rule for examining when the fruit list is the same list as the multiple object list:[/code]
and itâll work. (Iâd like to make that second formulation more elegant, so you could write âAn action on groups rule for examining the fruit listâ or something like that, but I donât see how.)
Anyway, hereâs the implementation! I ran into some weirdnesses, one of which was an abject failure and the other one of which Iâll probably post elsewhere so as to see if Iâm making a stupid mistake.
[spoiler][code]âThe Left Hand of Autumn, Refactoredâ by Emily Short with some changes from Matt Weiner
Section 1 - Acting on Groups and Stuff, Which could go in an extension if it were better organized
Multiple actions already taken is a truth state that varies.
Every turn:
now multiple actions already taken is false.
Action on groups is a rulebook. Action on groups has default failure.
An action-processing rule when the current action is groupable action and the multiple object list is not empty and multiple actions already taken is false (this is the check for group action rule):
follow the action on groups rules for the action name part of the current action;
if rule succeeded or rule failed:
now multiple actions already taken is true.
An action-processing rule when multiple actions already taken is true (this is the multiple actions preempt ordinary actions rule):
stop the action.
The check for group action rule is listed before the announce items from multiple object lists rule in the action-processing rulebook. [Could list it âfirstâ but I want to leave open the possibility of another extension putting another rule firstâall we need is to guarantee that it winds up before the announce items rule.]
The multiple actions preempt ordinary actions rule is listed after the check for group action rule in the action-processing rulebook.
The announce items from multiple object lists rule does nothing when multiple actions already taken is true.
To decide whether (list one - a list of things) is the same list as the multiple object list:
let list two be the multiple object list;
repeat with tester running through list one:
if tester is not listed in list two:
no;
repeat with tester running through list two:
if tester is not listed in list one:
no;
yes.
Section 2 - Some Other Code from âThe Left Hand of Autumnâ
[with a whole lot of stuff to handle multiple examining snipped]
After reading a command:
repeat through the Table of Collective Names:
let N be â[the playerâs command]â;
let Y be relevant list entry;
while N matches the regular expression â[name-text entry]â:
replace the regular expression â(.*)name-text entryâ in N with â\1[Y]\2â;
change the text of the playerâs command to N.
Report taking something:
say âYou pick up [the noun].â instead.
[and this next bit is commented out because itâd be too much work at the moment, but we might be able to do it by hand-changing the multiple objects list to L and then redirecting to examining]
[And as a bit of polish, because weâd like SEARCH TABLE to have the same effect as EXAMINE ALL ON TABLE:]
[Understand âlook on [something]â as searching.
Instead of searching something which supports at least two things:
let L be the list of things supported by the noun;
describe L.
Instead of searching something which contains at least two things:
let L be the list of things contained by the noun;
describe L.]
Section 3 - Scenario
Eight-Walled Chamber is a room. âA perfectly octagonal room whose walls are tinted in various hues.â
The display table is a supporter in the Chamber. A twig of rowan wood is on the table.
The player carries an apple and a pear.
A glove is a kind of thing. A glove is always wearable. Understand âgloveâ as a glove. The player carries a left glove and a right glove. The left glove and the right glove are gloves.
[Now we define a few actual lists of items:]
Fruit list is a list of things which varies. Fruit list is { apple, pear }.
Glove list is a list of things which varies. Glove list is { right glove, left glove }.
Arcane list is a list of things which varies. Arcane list is { left glove, twig, pear }.
[The following code is commented out because it is superseded by the new group action stuff.]
[To describe (L - a list of objects):
sort L;
if L is fruit list:
say âJust a couple of fruits.â;
otherwise if L is glove list:
say âItâs a matched pair of fuzzy blue gloves.â;
otherwise if L is arcane list:
say âTo anyone else it might look like a random collection of objects, but these three things â [L with definite articles] â constitute a mystic key known as the Left Hand of Autumn. They practically hum with power.â;
otherwise:
say âYou see [L with indefinite articles].â
When play begins:
sort fruit list;
sort glove list;
sort the arcane list.]
[We sort the lists so that regardless of how we change the rest of the code (and the order in which objects are coded), the resulting list will always be in sorted order and ready to compare with the list of items the player wants to look at. And thanks to the âReading a commandâ code we wrote earlier, we can also teach the game to understand the playerâs references to âthe left hand of autumnâ as a specific collection of items.]
Table of Collective Names
name-text relevant list
âleft hand of autumnâ â[arcane list]â
âglovesâ â[glove list]â
âpair of glovesâ â[glove list]â
Test me with âx apple and pear / x left and right / put pear on table / put left glove on table / x all on table / put all on table / examine all on table / get apple, twig, pear / x all on table / search tableâ.
Section 4 - Handling the Scenario with Action on Groups
Understand âexamine [things]â as examining.
Examining it from is an action applying to two things.
Understand âexamine [things inside] in/on [something]â or âlook at [things inside] in/on [something]â as examining it from.
Carry out examining it from: try examining the noun instead.
Examining is groupable action. Examining something from something is groupable action. Taking is groupable action. [We donât actually have any action on groups rules for takingâthis is just here to show that, when you donât have any action on groups rules, you get the ordinary behavior]
An action on groups rule for examining something from something:
try examining the noun. [putting this here instead of relying on the âcarry outâ rule allows us to suppress the announce items from multiple object lists rule when examining it fromâsince this rule succeeds, the multiple actions already succeeds flag gets set.]
An action on groups rule for examining when the fruit list is the same list as the multiple object list:
say âJust a couple of fruits.â
An action on groups rule for examining when the glove list is the same list as the multiple object list:
say âItâs a matched pair of fuzzy blue gloves.â
An action on groups rule for examining when the arcane list is the same list as the multiple object list:
say âTo anyone else it might look like a random collection of objects, but these three things â [multiple object list with definite articles] â constitute a mystic key known as the Left Hand of Autumn. They practically hum with power.â
Last action on groups rule for examining:
say âYou see [multiple object list with indefinite articles].â[/code][/spoiler]