Small chunk of 6.31 code for your scrutiny

Hopefully, this is the right forum to attempt asking for opinions on source writing! I arrived at the beginning of Chapter II in Nelson’s manual, and entered/understood the first bits of the Ruins game. I decided to add a couple flags that would render a different response to “examine” if the mushroom had already been nibbled, was being taken for the second time, etc. – as well as an attempt to keep the mushroom intact after it’s been tried, since the player’s death occurred if he takes two bites (i.e. after the first warning that it tastes awful). Can anyone comment on the efficiency and “correctness” of my embellishments so far? (It works perfectly, so I suppose this is mostly a stylistic query – although you might see something that I don’t even need. I’m brand-spankin’-new at this, after all.)
Thanks very much for any help!


[code]constant story “RUINS^”;
constant headline “An Interactive Example^Copyright (C)1999 by
Angela M. Horns. Edited 2007 by Chris Federico.^”;
include “Parser”;
include “VerbLib”;

! The “random” outcome will always be the same after saving the text
! (source) file, oddly enough – not after each compilation, which was
! the initial suspicion. Twenty tests were conducted for each case. The
! contents of the text file were not altered; the file was merely re-saved.
!
! The exception: If the PC has been rebooted, there will be a different
! result – once. But this will always be the same post-reboot result for
! that .z5 file. WinFrotz will return to repeating the other result after
! this first try, and will not waver unless the PC is rebooted yet again.
!
! There appears to be no way to scramble the seed to prevent this.
!
! In other words, avoid random numbers in Inform; use some other
! method to give the illusion of randomness if it’s ever necessary
! (i.e. particular combination of items carried, number of turns, etc.).

object forest “~Great Plaza~”
with description
“Or so your notes call this low escarpment of limestone;
but the rainforest has claimed it back. Dark olive trees
crowd in on all sides, the air steams with the mist of a
recent warm rain, and midges hang in the air.^
~Structure 10~ is a shambles of masonry that might
once have been a burial pyramid, and little survives
except stone-cut steps that lead into the darkness below.”,
has light;

! Using “describe” as below, rather than “initial,” prevents a blank
! line from being printed between the room description and the
! “object here” prose.

object->mushroom “speckled mushroom”
with name ‘speckled’ ‘mushroom’ ‘fungus’ ‘toadstool’ ‘growth’ ‘stalk’,
mushroom_picked,mushroom_tried,
describe [;
if(self.mushroom_picked)
“There’s a speckled mushroom here.”;
“A speckled mushroom grows from the sodden earth
on a long stalk.”;],
description
“It’s capped with blotches, and you aren’t at all sure it’s
not a toadstool.”,
before [; eat:if(self.mushroom_tried)
{deadflag=true;“Now you know beyond the shadow of a
doubt that it’s a toadstool.^
The poisonous kind, as it turns out.”;}
else
{print “You nibble at it, but the foul taste repels you.^”;
mushroom.description=“Now you’re almost positive it’s a
toadstool.”;
self.mushroom_tried=true;
move self to player;rtrue;}],

! The object move above is necessary to keep the mushroom from
! being removed from the game after it’s eaten; it’s being taken back
! from “nothing.” The “return true” keeps the library from inserting its
! own “eaten” message after the specially added (“nibble”) one.

after [; take:
if (self.mushroom_picked)
“Taken. I’m afraid you were only able to kill it the one time,
though.”;
self.mushroom_picked=true;
“You pick the mushroom, neatly cleaving its thin stalk.”;
drop:
“The mushroom drops to the ground, detached and not
very happy about it.”;],
has edible;

[initialise;location=forest;
“^^^After days of searching, days of thirsty hacking through the briars of
the forest, your patience is rewarded at last. An actual discovery!^”;];
include “Grammar”;[/code]

I can’t help (I’m a Hugo guy – sorry), but I did edit your message to add “code” quote tags around it. That should help on readability for whoever can answer you.

Thanks!
I appreciate that.

(I’ve had some discouraging responses from other IF authors I’ve e-mailed…“Oh, you won’t get anyone to help you out with Inform 6 anymore…all the rage now is Inform 7!” I’m thinking, well, it’s worth a try. :slight_smile: )

There does seem to be a rumour going around that hardly anybody uses Inform 6 any more, but I don’t think it’s true. More of the IFcomp 2007 games written in Inform used I6 than I7, if my memory serves me aright. In any case, the I6 experts who have switched to I7 haven’t forgotten their I6 yet (they need it for low-level Inform 7 hacking!), and will generally be happy to lend a hand.

However, it’s probably worthwhile downloading Inform 7 and having a look at it. I7 has some really nice features; it also has some rough spots. It’s basically a question of whether you prefer the style of I6 or I7. They are totally different languages, so it’s not particularly important that you learn I6 first. (In fact, I7 has been designed for beginners in a way I6 never was.)

Unfortunately, like Merk, I can’t help you with your code, since my system of choice is TADS 3!

Tangentially - I do encourage you to take the time to get the newsgroups working for you. They really are the hub of the English-speaking IF community, and you’re much more likely to get a quick answer to your questions there than anywhere else. If you can’t figure out how to get a newsreader working for you, try Google Groups. Google Groups can be annoying, but it’s pretty easy to use.

Your code seems reasonably efficient, though I recommend arrange your code so that the print statement is last whenever possible (second eat clause), and some general comments on style / readability:

  1. Always put a space between “if” and the paren.
  2. Always indent the “then” clause to an “if” or “else”.
  3. Put the first action in a before/after on a separate line.
  4. Indent properties.
  5. Put spaces around the equal sign.
  6. Unless the code is short enough to fit on a single line, put a newline immediately after a left brace.
object -> mushroom "speckled mushroom"
 with
   name 'speckled' 'mushroom' 'fungus' 'toadstool' 'growth' 'stalk',
   mushroom_picked,
   mushroom_tried,
   describe [;
     if (self.mushroom_picked)
       "There's a speckled mushroom here.";
     "A speckled mushroom grows from the sodden earth on a long stalk.";
   ],
   description
     "It's capped with blotches, and you aren't at all sure it's
      not a toadstool.",
   before [;
     eat:
       if (self.mushroom_tried) {
         deadflag = true;
         "Now you know beyond the shadow of a
          doubt that it's a toadstool.^
          The poisonous kind, as it turns out.";
       } else {
          mushroom.description = "Now you're almost positive it's a
            toadstool.";
          self.mushroom_tried = true;
          !move self to player; ! Returning true should prevent 
          "You nibble at it, but the foul taste repels you.";
       }
   ],
   after [;
     take:
       if (self.mushroom_picked)
         "Taken. I'm afraid you were only able to kill it the one time,
          though.";
       self.mushroom_picked = true;
       "You pick the mushroom, neatly cleaving its thin stalk.";

     drop:
       "The mushroom drops to the ground, detached and not
        very happy about it.";
   ],
   has edible;

Awesome. Thanks for the good advice!

Yes, 9 of the Inform games in this year’s comp were I6; the other 8 were I7.

I haven’t switched to I7 because I actually don’t like the idea of ‘natural language programming’. For me, programming shouldn’t be about trying to tell a computer to do something using your natural language - and certainly not a verbose language like English. I prefer the ‘programmatical’ nature of I6.

However, I have switched to using the integrated development environment for I7: you can get it at the I7 website. Not all of its features are relevant to I6 games, but I do find the Replay, syntax highlighting and file management features particularly useful so I would recommend taking a look. Although I do wish there were an easier way to navigate between functions and objects within a file - anyone know a good way of doing it?

Anyway, I’m happy to help if you post your queries on this forum.

Thanks so much, Kivie. I have the same opinion: I prefer a programming language-type language. And I’ve become obsessed with learning I6 and finally designing my own IF. Unless I eventually figure out how to get to Google Groups through the firewall at work (which I may never achieve), this forum’s my only lifeline, so I’m grateful that there are still folks willing to help a newcomer!