Making an Adventure Game - Part 3
- 3 minutes read - 632 wordsPreviously in this series: Part 1, Part 2,
Let’s crack on with the text!
If you’ve downloaded the git repo, then you’ll also have a folder called “src/”. There’s a file in there called “secrets-pyramids.tw”. That’s the actual game source file. It’s in twee-3 format, which is defined here. If you’re used to formatted text files, like Wiki format or Markdown, then twee-3 format shouldn’t look too weird to you.
I’ve found some conventions useful when creating the text, and some have been forced onto me. Here goes:
The tweego tool follows the format of your source text unexpectedly closely. This means that white space and line wrapping is important! You should format your text file with really long lines, rather than wrapping it. Use the word wrap feature in your editor to make the lines appear OK. If you don’t, you’ll get weird line breaks in the game. If you’re using VS Code (and you probably should), then you can just toggle word wrap on and you’re good to go.
The game format is centred around “passages”. Each non-special block that starts with two colons is a passage. I’ve found that it’s easiest to treat every page in the original book as a passage, at least as a starting point. This means that page 2 of the book is a passage block that looks like this:
:::page0002
The next few days are a blur of...Doing that has a bunch of advantages. First, it’s kind-of like how the original books work. Second, the original books have links that look like:
[If you hide, turn to page 34. If you run for it, turn to page 9.]
This maps neatly to references to page0034 and page0009, respectively.
Of course, you don’t have to do this,
but if you don’t, you’re going to end up doing a lot of extra work,
because links go to passages. The player never sees the location names
anyway, so it doesn’t matter. Note that these are the pages in the
book, which aren’t necessarily the same as the page numbers in the PDF.
Some pages won’t be relevant, because there are full-page graphics.
I’d advise not bothering with graphics unless they’re required to make
the story work. You can include them if you need to - of which more
later.
As for the links above, you can reword the text a bit, because you’re going to want to create a clickable action link, and the link text should be an action. So, the example above becomes:
Do you [[hide->page0034]] or [[run for it->page0009]]?The player will see this as:
Do you hide or run for it?
And, of course, clicking the link takes you to the next passage in the story.
Once you have a bit done, you can use the appropriate “build” command to make the playable HTML appear. When you do, you’ll notice quite quickly that you don’t have a really playable game yet. The game jumps around in the book quite a lot, so that it’s harder to get a feel for where you are. As we’re reading the book linearly, we’ll be filling in chunks of text as we go, and the game won’t be playable until you’re done.
When you do build the game, you’ll hit an error about there not being a unique ID in the game. The tool will give you the block of data you need to insert. Do that, but add it as a separate file (called something like “storydata.tw”) in the src directory containing just the block the tool points you to. tweego will pick up everything relevant to it in the src folder without you having to do anything.
At this point, you can keep going, ensuring that you stick to the twee-3 format.