Print Newline After Listing Last Initial Description

I have a small printing problem, I searched the forums but could not find a similar post. Any tips to steer me in a the right direction will be appreciated.

I created a DoorWay class that lists the exits via initial descriptions, the problem is,
the lounge lists the front door and the narrow passage, with the prompt printed below this output without a newline. On the other hand, when in the kitchen and because the watermelon and pumpkin are listed, there is a newline before the next prompt.

This sample transcript demonstrates my problem:

In the Lounge
The lounge is nondescript.

A front door is to the south.
A narrow passage is to the east.
> go passage

In the Kitchen
The kitchen is nondescript.

A narrow passage is to the west.
You can also see a watermelon and a pumpkin here.


It is a trivial issue, but I would like to solve this problem by having consistent output, preferably with a newline printed after the last DoorWay is printed.

Am I going about this the wrong way by using the initial descriptions as my listing mechanism? And if so, what would be a better approach to this?

Below is the listing of my sample code:

!% -SD
Constant Story "";
Include "Parser";

! A door that is listed in the room description.
Class DoorWay
    initial [;
        if (self.door_dir() == u_to) {
            print (A) self, " leads upward. ";
        } else if (self.door_dir() == d_to) {
            print (A) self, " leads downward. ";
        } else {
            print (A) self, " is to the ", (name) self.door_dir(), ". ";
has static door open;

[ Initialise;
  location = lounge;
  move pumpkin to kitchen;
  move watermelon to kitchen;

Object lounge "In the Lounge"
with description "The lounge is nondescript.",
e_to passage,
has light;

Object kitchen "In the Kitchen"
with description "The kitchen is nondescript.",
w_to passage,
has light;

Object pumpkin "pumpkin"
with name 'pumpkin';

Object watermelon "watermelon"
with name 'watermelon';

DoorWay passage "narrow passage"
    name 'passage',
    found_in lounge kitchen,
    door_to [;
      if (location == lounge) return kitchen;
      return lounge;
    door_dir [;
      if (location == lounge) return e_to;
      return w_to;

DoorWay front_door "front door"
  name 'front' 'door',
  found_in lounge,
  door_dir s_to;

Include "VerbLib";
Include "Grammar";

I think what you need to do is to make a variable keep track whether you’ve printed something (i.e. initially false but set to true in each of the if blocks), and if that’s true at the end then print "^".

Oh right, ignore me, sorry. I was misreading that to think you were walking through each exit in a loop, who knows why.

If you don’t want to have the newlines between different exits at all, then you probably can’t do that with the initial property. Instead you’ll probably want to hook into after ##Look and write that sort of loop that I described above. If you were using I7, I could suggest several extensions that do this (one of which I wrote myself), but my I6 is a little too rusty to offer an example of this, sadly.

The rule is that the initial property must end its output with a newline, unless it prints nothing at all.

Thanks for the suggestion @mirality, I looked up actions in the DM4 and found a way that accomplishes what I want - Removing the initial descriptions and using objectloop in combination with a ##Look action test.

Also, thanks for mentioning that initial rule @zarf, this also solves the problem, albeit with a sparser output, which is at least consistent. I will keep this rule in mind for all my other initial descriptions, it highlights that initial is probably not the best way to solve this.

(for posterity, here are the changes made)

Class DoorWay
has static door open scenery;

Class Room
  after [item;
    if (action == ##Look) {
      objectloop(item in location) {
        if (item ofclass DoorWay) {
          print (A) item, " is to the ", (name) item.door_dir(), ". ";
      print "^";