Inform - Resources - Examples

Back to List

Inventory
Complete

At Start
Forward

Plain
Coloured
Gaudy

This code
in plain text

Browsing Balances.inf

1. Balances.inf begins (lines 1-160)

0001  ! ----------------------------------------------------------------------------
0002  !   Balances 961216                 One of the standard Inform 6 example games
0003  !
0004  !                                                             created: 25.9.94
0005  !                                                             updated: 6.10.94
0006  !                                                         modernised: 11.12.95
0007  !                                               translated to Inform 6: 8.5.96
0008  !                                                   minor bugs fixed: 16.12.96
0009  !
0010  !   This short story was written to demonstrate large-scale programming of
0011  !   the parser, and features multiple objects, complicated plurals, variable
0012  !   verbs, objects named by the player and questions.  The spell-casting
0013  !   system is written in a "safe" way so that it could easily be transplanted.
0014  !
0015  !   Needs Inform 6, library 6/1 or later to compile.
0016  ! ----------------------------------------------------------------------------
0017   
0018  Release 5;
0019  Serial "961216";
0020  Switches d;
0021   
0022  Constant Story "BALANCES";
0023  Constant Headline "^An Interactive Short Story
0024                     ^Copyright (c) 1994, 1995, 1996 by Graham Nelson.^";
0025   
0026  Constant OBJECT_SCORE 5;
0027  Constant MAX_SCORE 51;
0028   
0029  Include "Parser";
0030  Include "VerbLib";
0031   
0032  ! ----------------------------------------------------------------------------
0033  !   The white featureless cubes from "Spellbreaker", which can be identified
0034  !   by being written on with the magic burin, so that their names are given
0035  !   by the player in the course of play
0036  !
0037  !   A particularly witty thing to do is to give several of them the same name,
0038  !   or to frotz some of them to distinguish them from the others...
0039  !   And the game will have no problem with this.
0040  ! ----------------------------------------------------------------------------
0041   
0042  Array cube_text_buffer -> 8;
0043  Global the_named_word = 0;
0044  Global from_char; Global to_char;
0045   
0046  Class  FeaturelessCube
0047    with number 0 0 0 0,   ! There's room for 8 bytes of text in these 4 entries
0048         description "A perfect white cube, four inches on a side.",
0049         parse_name
0050         [ i j flag;
0051              if (parser_action==##TheSame)
0052              {   for (i=0:i<8:i++)
0053                      if ((parser_one.&number)->i
0054                          ~= (parser_two.&number)->i) return -2;
0055                  return -1;
0056              }
0057              for (::i++)
0058              {   j=NextWord(); flag=0;
0059                  if (j=='cube' or 'white' ||
0060                      (j=='featureless' or 'blank' &&
0061                             ((self.&number)->0) == 0)) flag=1;
0062                  if (j=='cubes')
0063                  {   flag=1; parser_action=##PluralFound; }
0064                  if (flag==0 && ((self.&number)->0) ~= 0)
0065                  {   wn--;
0066                      if (TextReader(0)==0) return i;
0067                      for (j=0: j<8: j++)
0068                          if ((self.&number)->j ~= cube_text_buffer->j)
0069                              return i;
0070                      flag=1;
0071                  }
0072                  if (flag==0) return i;
0073              }
0074         ],
0075         article "a",
0076         short_name
0077         [ i; if (((self.&number)->0) == 0) print "featureless white cube";
0078              else
0079              {   print "~";
0080                  while (((self.&number)->i) ~= 0)
0081                      print (char) (self.&number)->i++;
0082                  print "~ cube";
0083              }
0084              rtrue;
0085         ],
0086         plural
0087         [;   self.short_name(); print "s";
0088         ],
0089         baptise
0090         [ i; wn = the_named_word;
0091              if (TextReader(1)==0) return i;
0092              for (i=0: i<8: i++)
0093                  (self.&number)->i = cube_text_buffer->i;
0094              self.article="the";
0095              print_ret "It is now called ", (the) self, ".";
0096         ],
0097    has  scored;
0098   
0099  !  Copies word "wn" from what the player most recently typed, putting it as
0100  !  plain text into cube_text_buffer, returning false if no such word is there
0101   
0102  [ TextReader flag point i j len;
0103   
0104     if (flag==1 && from_char~=to_char)
0105     {   for (i=from_char, j=0:i<=to_char && j<7:i++)
0106         {   cube_text_buffer->j = buffer->i;
0107             if (buffer->i ~= ' ' or ',' or '.') j++;
0108         }
0109         for (:j<8:j++) cube_text_buffer->j = 0;
0110         from_char=0; to_char=0;
0111         rtrue;
0112     }
0113   
0114     for (i=0:i<8:i++) cube_text_buffer->i = 0;
0115     if (wn > parse->1) { wn++; rfalse; }
0116     i=wn*4+1; j=parse->i; point=j+buffer; len=parse->(i-1);
0117   
0118     for (i=0:i<len && i<7:i++) cube_text_buffer->i = point->i;
0119   
0120     wn++; rtrue;
0121  ];
0122   
0123  Object burin "magic burin"
0124    with name "magic" "magical" "burin" "pen",
0125         description
0126            "This is a magical burin, used for inscribing objects with words
0127             or runes of magical import. Such a burin also gives you the
0128             ability to write spell scrolls.",
0129         before
0130         [; WriteOn:
0131               if (second ofclass FeaturelessCube)
0132               {   if (second notin player)
0133                       "Writing on a cube is such a fiddly process that you
0134                        need to be holding it in your hand first.";
0135                   if (burin notin player)
0136                       "You would need some powerful implement for that.";
0137                   second.baptise();
0138                   rtrue;
0139               }
0140               if (second ofclass SpellBook)
0141                   "If a burin could write in a spell book, you wouldn't need
0142                    the gnusto spell!";
0143               if (second ofclass Scroll)
0144                   "You cannot write just anything on the magic parchment of
0145                    a scroll: you can only ~copy~ a spell to it.";
0146         ];
0147   
0148  [ WriteOnSub; "Graffiti is banned."; ];
0149   
0150  [ CopyToSub;
0151    if (burin notin player) "You need to be holding the burin to copy a spell.";
0152    if (second ofclass SpellBook)
0153        "If a burin could write in a spell book, you wouldn't need
0154         the gnusto spell!";
0155    if (~~(second ofclass Scroll)) "You can only copy spells to scrolls.";
0156    if (child(second)~=0)
0157        "The scroll is already full of incantation.";
0158    "The scroll is not blank, only illegible.";
0159  ];
0160   


Last updated 23 June 2004. This web site has not been fully supported since April 2008. Information may be out of date. This page was originally managed by Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight.