Inform - Resources - Examples

Back to List

Inventory
Complete

Backward
Forward

Plain
Coloured
Gaudy

This code
in plain text

Browsing Toyshop.inf

White Gloves (lines 385-455)

385  ! >GL  The following example, suggested to the author by Richard Tucker,
386  !      demonstrates an apparently tricky case of objects with associated
387  !   sub-objects.  The pair of white gloves behaves just like any other item
388  !   of clothing - but the player can also use the left and right gloves
389  !   independently, can take away or wear only one and so on.  When they
390  !   come back together (even in a cupboard, say, or on a mantelpiece)
391  !   they are called a pair again.
392  !
393  !   We can do this with only three objects, one daemon and one rule.
394  !   
395  !   When the gloves are together, and the player refers to an individual
396  !   glove, the before rule splits up the pair and starts the daemon.
397  !   Once active, the daemon tries every turn to re-join them into a pair.
398  !   (If it succeeds, it turns itself off.)
399  !
400  !   Note that the "pair of gloves" object has the "general" attribute exactly
401  !   when the gloves are apart.  Otherwise the pair-object contains both
402  !   glove objects, and has "transparent" so that the parser knows the player
403  !   can see and refer to them.
404  ! ----------------------------------------------------------------------------
405   
406  Object -> gloves "white gloves"
407    with article "a pair of",
408         name "white" "gloves" "pair" "of",
409         daemon
410         [;  if (parent(right_glove) ~= parent(left_glove)) return;
411             if ((left_glove has worn && right_glove hasnt worn)
412                 || (left_glove hasnt worn && right_glove has worn)) return;
413             if (left_glove has worn) give gloves worn; else give gloves ~worn;
414             move gloves to parent(right_glove); give gloves ~general;
415   
416             move right_glove to gloves; move left_glove to gloves;
417             give right_glove ~worn;     give left_glove ~worn;
418             
419             StopDaemon(self);
420         ],
421    has  clothing transparent;
422   
423  Class  Glove
424    with article "the",
425         name "white" "glove",
426         before
427         [;  if (self notin gloves) rfalse;
428             move left_glove to parent(gloves); move right_glove to parent(gloves);
429             if (gloves has worn)
430             {   give left_glove worn; give right_glove worn;
431             }
432             give gloves general; remove gloves;
433             StartDaemon(gloves);
434         ],
435    has  clothing;
436   
437  Glove -> -> left_glove "left glove"
438    with description "White silk, monogrammed with a scarlet R.",
439         name "left";
440  Glove -> -> right_glove "right glove"
441    with description "White silk, monogrammed with a scarlet T.",
442         name "right";
443   
444  ! ----------------------------------------------------------------------------
445  !   ...and that's all: the "gloves" code is self-contained.
446  !
447  !   Exercise for the reader: hide a (sharp) jewel inside the left glove.
448  !     (Alter the glove class to make them containers open only when not worn.
449  !      Add two "after" rules to warn the player if there's something sharp
450  !      to the touch, one for putting on the pair of gloves, one for putting on
451  !      an individual glove.)
452  ! ----------------------------------------------------------------------------
453   
454   
455  ! ----------------------------------------------------------------------------


Last updated 23 June 2004. This site is no longer supported; information may be out of date.
Maintained as a historical archive by the Interactive Fiction Technology Foundation. Copyright 1993-2018 IFTF, CC-BY-SA unless otherwise noted.
This page was originally managed by Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight.