multiple HTML file creation for nonlinear story telling

(This post focuses on HTML because my understanding is EPUB and MOBI do not fully support what I’m about to suggest. I’d love to know if I’m mistaken.)

Suppose one wanted to write a Chose Your Own Adventure story. It seems to me that instead of generating a single monolithic HTML file, a more appropriate form would be to have multiple HTML files, where one is the starting point, and others are reached only through hyperlinks.

(Although my project is not an adventure story, it does have a similar nonlinear nature.)

I’d love to have this as an HTML-compile option… or to know if there’s something I’m overlooking.

Epub and Mobi should be able to do this just fine. Internally, they are separate HTML files inside a zip file, and support linking between different documents. So this would be best done as an ePub ebook, I think.

All the best,

Thanks, but it’s not the linking between documents I’m concerned about; I’m concerned about restricting access to only the links, as opposed to letting the reader access all content by paging forward.

To make sure I’m clear about the restriction I’m referring to…
suppose “a.html” contains:

The **ONLY** way to see the exciting conclusion is to use <a href="b.html">this link.</a>

I can create a MOBI containing a.html and b.html, and the link works fine. But in my trials, the reader can also read “b.html” by paging forward, which I don’t want.

I was told MOBI doesn’t support this. That’s why I was hoping for a chance to achieve this through separate HTML file generation. If MOBI does in fact support this restriction, I’d love some hints on how to achieve it.

How will a reader access these html files?

Would have to be some kind of web browser, it seems to me. Or a dedicated hypertext reader/authoring tool like StorySpace. (


Which, to me, would be easy to circumvent and read in any order I want. I’m thinking, that to really prevent someone like me from skipping ahead, you’re looking at flash or some other encapsulating app.

Either way I wonder if maybe the issue isnt really worth the effort. Guys like me will almost always get to the data if we want too.

But I may be evil. :imp:

Well, presumably a reader who chooses a non-linear story has some willingness to “play along” with the trope and not put effort into circumventing it. So the mechanism doesn’t need to be strong enough to withstand a dedicated attack, it just needs to prevent casual or accidental mis-navigation.


One solution:

  1. Compile to ePub.

  2. In the options area of Compile, tick “Save source files in a folder with exported ePub file”.

  3. Discard all the files you don’t need (the .ePub file, contents file etc) and just keep the HTML, CSS and any image files you need for your book.

All the best,

Solution two: scramble the order of everything after the first entry. That’s how physical “choose your own adventure” books used to work. Also, there are tools for building interactive fiction that might be better suited to obscuring the underlying story chapters. Here’s a link to a number of open source tools I found at the top of a google search results page:

That’s a very good point - I could skip through the pages of the Choose Your Own Adventure books I had as a kid, so using an ebook would be no different from having a print version…

How about the new feature (ePub3/KF8) that can hide a Section Layout from typical navigation methods and make it only accessible via direct links? To test:

  1. Edit your compile format and go into the Section Layouts pane.
  2. Click on the layout currently being used for normal sections and click the + button to duplicate it.
  3. In the “Settings” tab, click the Hide section in e-book option.
  4. Save the format and back in the compile overview screen, click the Assign Section Layouts… button. Select the section type on the right, and assign your new “hidden” section layout to it.
  5. Finally, ensure Convert document links to HTML links is enabled in the general options tab on the right, and compile.

In my testing, whether or not it is really hidden is kind of up to the reader software. Calibre’s eBook viewer for example will blithely ignore that anything is hidden and allow full page to page navigation. But iBooks and Adobe Digital Editions (which together account for most eBook reading software and devices outside of Kindle) do seem to produce the desired result.

The main drawback is that normal page to page navigation becomes completely inoperable. You can page through a section, but once you get to the end of the section the only way out of it is through a hyperlink or via some “Back” button capability in the reader. That may however be considered a feature in this case.

I haven’t tested it, but this should work with Kindles as well.

My intent is to have the content accessed through links.

Agreed, and well-put. I don’t see being able to circumvent the trope as being any more of a problem than a reader being able to skip to the last chapter of a mystery novel.

Excellent! Thanks for the idea. That should solve the HTML side; now to explore what’s possible in EPUB (which I’m now considering thanks to Amber’s post…)

Thank you, this sounds promising! However, you lost me on step 3. This is what I see… am I in the wrong place?

Ah, but Kindles don’t support EPUB. Or did you mean to use the same compile technique for MOBI?

You need to be editing the format itself, rather than the project’s compile settings (which can be seen in the screenshot). Over in the leftmost column are your formats. Right-click on the one that is highlighted and edit it. You might need to duplicate it first if it is a built-in format. The instructions should make more sense once you’re in the right place.

Well yes and no. KDP does accept ePub files on upload (they will convert it for you to a format Kindles can read), but you can also compile straight out of Scrivener using the “KF8” compile type, at the top. I’d recommend the latter along with some testing in their software/devices since this is an unusual approach.

Thanks for the suggestions. In my case, I don’t see scrambling the order to be as helpful as it would be for an adventure story. (I used Choose Your Own Adventure as a close-enough reference point. I’m writing a Platonic dialog and I want to encourage the reader to pursue whatever points pique their interest. It remains to be seen whether it’s desirable to implement a Platonic dialog this way, but I want to try it.)

It’s good to learn the existence of these tools (also of Storyspace; thanks Katherine), but I’d like output that can be consumed by standard ebook readers.

Ah, yes, thank you.

I think I followed the instructions (.scriv file attached in case you can point out where I did not), and generated an epub file. Here’s what I found:

In iBooks, I can’t get past the TOC. (Could be something simple I’m doing wrong?)
In Adobe Digital Editions, the content is not hidden as desired.

I also tried compiling without the option “Generate HTML table of contents” in an attempt to test in iBooks. This time, iBooks reported the file was corrupt, and Adobe Digital Editions reported “Errors were encountered in this item”.

As always, I appreciate any insight.
Nonlinear (13.7 KB)

You’re just in the basic options there - you’ll need to delve a bit deeper for this by creating your own Compile format. Click on the gear icon below the Formats list and either create a new Format or duplicate and edit the Ebook format. You’ll most likely want to check out our video tutorials on Compile at this point, because once you start editing and creating Compile formats there are a lot of options. :slight_smile:

All the best,

Great, it looks like you have all of the major ingredients in place and figured out. There are a few tweaks you would need to make in order to make this approach work, and ultimately work more intuitively:

  • You probably do not need the HTML ToC since there is only one point of entry for the rest of the book—but I would consider adding an informal one, one that actually does have a cheat sheet list to every section, but isn’t designated as a regular ToC. Why? If someone loses their place somehow, they will be entirely unable to get back to where they were, short of following the whole long chain all over again—a bit like watching a David Lynch DVD. So some kind of “appendix” entry at the end that maybe has a paragraph explaining spoilers are to follow, and the role of the hyperlink list, could be valuable.

So in the ToC tab of the compile overview screen, I disabled Generate HTML table of contents (I believe you got errors trying that before because removing that section left not a single public section available, thanks to the problem described in the next bullet). I didn’t bother making a cheat sheet for this simple test—I just mention that more for future reference. It isn’t necessary to making this technique work.

  • Next up: the reason your sample isn’t working properly is that your “Hidden” Section Layout isn’t generating proper section breaks. If you look at the Section Layouts preview column in compile overview, you’ll note that the “Hidden” preview tile stipulates section breaks will occur for folders only. So what is happening is “The end!” is getting glued onto the end of the one section you meant to have as the entry point, which is in turn making that section invisible as well. Thus the only visible content in your eBook is the ToC page, which is empty because all sections in the book are invisible.

Solution: go into the Separators compile format pane and for the “Hidden” layout, disable defaults. That should be all you need to do, since your underlying settings for that layout are for “Section Breaks” both before and between hidden sections.

  • The last ingredient you need to make this work is hyperlinks. :slight_smile: Back in the general options tab on the overview screen (where you posted your initial screenshot), ensure Convert document links to HTML links is enabled. At the moment your link to “The end!” is stripped out, leaving it entirely inaccessible.

Give that a test compile, and now you should have a book that opens directly to the starter page.