Quick tip: adding multiple newlines in Dialog

Hey there!

I dipped my toes in Dialog years ago when Tethered was first released, but today I’ve been really making a concerted effort to learn how to write in it. I ran into a bit of an edge case that stumped me and couldn’t find a way around it in the documentation so, when I figured it out, I figured I would share it here.

By default, Dialog does not like multiple line breaks or paragraph breaks. This makes sense when you consider that most of the time you don’t need multiple paragraph breaks, but I find it more aesthetically pleasing when you get to a game over screen to have it be separated by a few lines from the game text to kind of signify that it’s metatext and not in-game text.

After some messing around, I’ve found a method that seems to work.

(space) without any numbers waits for text input and then forces a space before the next character, but (space n) with n as a number adds that many spaces arbitrarily without it being caught in the whitespace collector.

So, I’ve started making space sandwiches to separate out my game over text by doing this:

(par)
(space 5)
(par)
(space 5)
end game text!
(game over {You win! })

I hope this helps anyone running into the same question! I’m trying to build up reference sheets of helpful hints, and once I figured out the multiple newlines trick I immediately added it to my sheet.

If I missed this in the documentation somewhere, or if there’s a more elegant way of doing this, please let me know :sweat_smile:

2 Likes

I totally forgot to show the output.

Here’s what it looks like when I run my game through frotz:

Below the study
A small cellar beneath the study. Creepy!





You solved the mystery of the cellar!

     *** You win! ***

Would you like to:
     UNDO the last move,
     RESTORE a saved position,
     QUIT the program,
     or RESTART from the beginning?
> quit

Thanks for playing!
[Hit any key to exit.]
2 Likes

I think the “correct” way to have multiple lines is to add some margin with a CSS declaration. I haven’t tested, but something like that:

(style class @game-over-message)
    margin-top: 6em;

(win the game)
    (div @game-over-message) {
        You solved the mystery of the cellar!
    }
    (game over { You win! })

It should look the same on the Z-machine, but will look better on the Å-machine than having several paragraph breaks (and will be more flexible sine you can use any CSS property).

If you don’t have the “You solved…” message before the game over, then maybe you could just add an empty div before the game over with (@div @game-over-message) {}?

Or, likely better, you could directly apply the div to the “*** You win! ***” message by redefining the (game over $) rule:

%% It's a copy of the rule from stdlib, with an added div.
(game over $Message with margin)
    (par)
    (div @game-over-message) {
        (space 5)
        (span @bold) { \*\*\* (query $Message) \*\*\* }
    }
    (game over)

(It might be possible to simply use (div @game-over-message) (game over { You win! }) instead of redefining it, but the game over rule changes the status line and I believe it’s illegal to enter the status line while inside a div. And also the whole final question business will be in that div in that case, which might not be ideal.)

3 Likes

Oh thanks! I’ve been testing mostly on the Z-machine, and hadn’t even thought that it would cause problems on the Å-machine. I’ll try these out and see which one works best.

1 Like

I don’t think it would cause problems on the Å-machine per se. It’s just that for the web interpreter, a margin is a better practice than a couple of empty <p> elements.

And if you’re targeting the Å-machine exclusively, you can have a more fine-grained margin. Say 4.5em or 50px or any CSS length. (When targetting the Z-machine, only whole em are valid. Not sure if it’ll round the value if a decimal is provided.)

3 Likes

Good to know! I have plans of eventually releasing a game on the Å-machine to my website, so I’ll keep all that in mind. I’ll play around with what you’ve mentioned later and add it to my reference once I find one that feels good.

1 Like