! >GL The following example, suggested to the author by Richard Tucker, ! demonstrates an apparently tricky case of objects with associated ! sub-objects. The pair of white gloves behaves just like any other item ! of clothing - but the player can also use the left and right gloves ! independently, can take away or wear only one and so on. When they ! come back together (even in a cupboard, say, or on a mantelpiece) ! they are called a pair again. ! ! We can do this with only three objects, one daemon and one rule. ! ! When the gloves are together, and the player refers to an individual ! glove, the before rule splits up the pair and starts the daemon. ! Once active, the daemon tries every turn to re-join them into a pair. ! (If it succeeds, it turns itself off.) ! ! Note that the "pair of gloves" object has the "general" attribute exactly ! when the gloves are apart. Otherwise the pair-object contains both ! glove objects, and has "transparent" so that the parser knows the player ! can see and refer to them. ! ---------------------------------------------------------------------------- Object -> gloves "white gloves" with article "a pair of", name "white" "gloves" "pair" "of", daemon [; if (parent(right_glove) ~= parent(left_glove)) return; if ((left_glove has worn && right_glove hasnt worn) || (left_glove hasnt worn && right_glove has worn)) return; if (left_glove has worn) give gloves worn; else give gloves ~worn; move gloves to parent(right_glove); give gloves ~general; move right_glove to gloves; move left_glove to gloves; give right_glove ~worn; give left_glove ~worn; StopDaemon(self); ], has clothing transparent; Class Glove with article "the", name "white" "glove", before [; if (self notin gloves) rfalse; move left_glove to parent(gloves); move right_glove to parent(gloves); if (gloves has worn) { give left_glove worn; give right_glove worn; } give gloves general; remove gloves; StartDaemon(gloves); ], has clothing; Glove -> -> left_glove "left glove" with description "White silk, monogrammed with a scarlet R.", name "left"; Glove -> -> right_glove "right glove" with description "White silk, monogrammed with a scarlet T.", name "right"; ! ---------------------------------------------------------------------------- ! ...and that's all: the "gloves" code is self-contained. ! ! Exercise for the reader: hide a (sharp) jewel inside the left glove. ! (Alter the glove class to make them containers open only when not worn. ! Add two "after" rules to warn the player if there's something sharp ! to the touch, one for putting on the pair of gloves, one for putting on ! an individual glove.) ! ---------------------------------------------------------------------------- ! ----------------------------------------------------------------------------