The TADS Alternate Library
Version 2.0
List Grouping
Copyright 2000 by Kevin Forchione.
This is part of the TADS Alternate Library Authors Manual.
Introduction and Table of Contents
List Grouping[1]
The Alt general listing
produced by listContGen() is capable of producing a variety of general listings
including the following:
HTML TADS - A multimedia TADS
2.5.2 Interpreter.
Copyright (c) 1993, 2000
by Michael J. Roberts.
Welcome to TADS Alternate
Library...
An Interactive Fiction
Release 1 / Serial number
000404
Alt Library Version 1.0.2
Entryway
This large, formal entryway is slightly intimidating: the
walls are lined with somber portraits of gray-haired men from decades past; a
medieval suit of armor, posed with battle axe at the ready, towers over a
single straight-backed wooden chair. The front door leads back outside to the south.
A hallway leads north. There is a small sign here.
The glass bottle is open.
There's a beach ball here.
The front door is closed.
You can also see 3 hats (one fez, one Panama, and one
sombrero); 9 coins (four silver, two bronze, and three gold); and the letters
X, Y, and Z from a Scrabble set here.
>
The last line of this
listing demonstrates Alt List Grouping. This feature allows an author to
sublist objects according to abstract groupings such as “hats” or “coins” and
to prefix and suffix these sublist with messages and counts. Objects which are
listed together are displayed thus anytime they are presented through
listContGen(). They are even listed together in for aggregate display purposes:
>take gold and silver
coins
5 coins (one gold and four
silver): Taken.
To use this special
feature you need to create a ListGroup object. Next give your game objects a
listTogther attribute that points to this ListGroup object. Finally provide
each object with the groupDesc and groupPluralDesc attribute used to describe
itself when it appears in a ListGroup sublist.
For example, to produce
the list group display for the Scrabble pieces above, we defined the following:
scrabbleTileListGroup:
ListGroupMessage
groupPrefix = "the letters "
groupSuffix = "from a Scrabble set"
;
class ScrabbleTile: Item
listTogether = scrabbleTileListGroup
sDesc = "Scrabble letter <<groupDesc>>"
adjective = 'letter'
plural = 'letters'
;
x: ScrabbleTile
location = entryway
groupDesc = "X"
noun = 'x'
;
y: ScrabbleTile
location = entryway
groupDesc = "Y"
noun = 'y'
;
z: ScrabbleTile
location = entryway
groupDesc = "Z"
noun = 'z'
;
Alt provides a general ListGroup
class and two more specialised classes: ListGroupMessage and
ListGroupParenCount an author can use as superclasses for their ListGroup
object.
ListGroupMessage: This class prefixes the sublist with the object’s groupPrefix and suffixes the list with the groupSuffix. Display takes the form groupPrefix <sublist> groupSuffix.
ListGroupParenCount: This class prefixes the sublist with a count of the objects in
the sublist, followed by the groupPrefix, followed by a parenthesis, then the
sublist, another parenthesis, and finally the groupSuffix. Display takes the
form sublistCount groupPrefix ( sublist ) groupSuffix.
An example, using the ListGroupParenCount class:
coinListGroup:
ListGroupParenCount
groupPrefix = "coins"
;
class SilverCoin: Item
location = entryway
isEquivalent = true
plural = 'coins'
noun = 'coin'
adjective = 'silver'
sDesc = "silver coin"
pluralDesc = "silver coins"
groupDesc = "silver"
pluralGroupDesc = "silver"
listTogether = coinListGroup
;
coin1: SilverCoin;
coin2: SilverCoin;
coin3: SilverCoin;
coin4: SilverCoin;
class BronzeCoin: Item
location = entryway
isEquivalent = true
plural = 'coins'
noun = 'coin'
adjective = 'bronze'
sDesc = "bronze coin"
pluralDesc = "bronze coins"
groupDesc = "bronze"
pluralGroupDesc = "bronze"
listTogether = coinListGroup
;
coin5: BronzeCoin;
coin6: BronzeCoin;
class GoldCoin: Item
location = entryway
isEquivalent = true
plural = 'coins'
noun = 'coin'
adjective = 'gold'
sDesc = "gold coin"
pluralDesc = "gold coins"
groupDesc = "gold"
pluralGroupDesc = "gold"
listTogether = coinListGroup
;
coin7: GoldCoin;
coin8: GoldCoin;
coin9: GoldCoin;
This produces the display:
9
coins (four silver, two bronze, and three gold).
The ListGroup object may
define a groupPrefix and groupSuffix for the sublist. Both the ListGroupMessage
and ListGroupParenCount class do not display the groupPrefix or groupSuffix
when the sublist consists of one set of objects, even if that set consists of
multiple indistinguishable objects. For example, if we take the gold coins and
check our inventory:
>take gold coins
three gold coins: Taken.
>i
You have a rucksack (being
worn) and three gold coins.
The gold coins are
displayed normally. But if we take the bronze coins and check our inventory:
>take bronze coins
two bronze coins: Taken.
>i
You have a rucksack (being
worn) and 5 coins (three gold and two bronze).
The coins are listed
together using their ListGroup object definition.
Every thing class object
inherits groupDesc and groupPluralDesc attributes. The groupDesc attribute
default is sdesc, while the groupPluralDesc default is pluraldesc. Use the
groupDesc and groupPluralDesc attributes to describe the objects as you wish
them to appear in the ListGroup sublist. When objects are not grouped in a
ListGroup display or the sublist of the ListGroup consists of only one set of
objects then they are displayed using the normal rules for listContGen().
For instance, in our coin
example above, if all we are holding are the bronze coins then when we check
our inventory we see:
>i
You have two bronze coins.
which
is what we would expect, rather than “You have two bronze”. Using groupDesc and
groupPluralDesc allows an author to tailor the sublist display flexibly.
[1] We are greatly indebted to Michael J. Roberts for outlining much of the details of the ListGroup class, and for providing sample coding demonstrating how it should work.