There’s a new version of ChoiceScript available from Github that handles a very subtle bug.
Meet the “Titan Submersible Bug”
There’s a weird kind of bug that can happen in a ChoiceScript game. I’m calling this bug the “Titan Submersible Bug.” The Titan Submersible Bug happens when you use *gosub_scene
but you forget to *return
.
(The bug is named after a famous submarine that did not successfully return to the surface.)
Here’s how *gosub_scene
is supposed to work, with *return
For example, let’s say you have a file called chapter3.txt
, with code like this:
*comment chapter3.txt
Start of chapter 3.
*gosub_scene tools
The rest of chapter 3.
And then, in tools.txt
, you have code like this:
*comment tools.txt
example code, lorem ipsum, etc. etc.
*return
When you *return
from tools.txt
, the player will jump back to where they left off in chapter 3, allowing them to read the rest of chapter 3.
In the Titan Submersible Bug, you forget to *return
Perhaps tools.txt
might look like this, instead:
*comment tools.txt
example code, lorem ipsum, etc. etc.
*goto_scene chapter4
Since the *return
is missing, players would shoot straight on ahead to Chapter 4, without seeing the rest of Chapter 3.
The Titan Submersible Bug created a major issue when submitting post-release updates
The details are… a lot. So I’m going to put them in a collapsible details section here.
Click here to see the full story
“Autosaves” vs. “Backup” saves, for updating
When you play published ChoiceScript games (on our website, in our apps, or if you export your game using the Export to HTML tool), ChoiceScript automatically keeps an “autosave” as you play. The autosave includes all of your current stats and temps, and it includes the name of the file you’re currently in, (e.g. chapter6.txt
) and the line number you’re currently on.
The “autosave” ensures that if you quit the app or refresh the page, you can continue playing where you left off.
autosave:
file: chapter6.txt
line: 1234
strength: 57
leadership: 68
...
But that won’t work if you’re playing halfway through chapter6.txt
and then we have to update the file while you’re playing. If you paused playing the game at line number 1234, what does “line number 1234” mean when chapter6.txt
has changed? In the old version of chapter6.txt
, line number 1234 might have been the result of a major *choice
, but in the new version of chapter6.txt
, that could be smack dab in the middle of a paragraph.
To workaround this, whenever you enter a new scene/chapter file, we record a “backup” save, including all of your stats, with the “line number” set to line 1.
When we update the game, we check to see if the scene file you’re currently in has changed. If it has changed, we throw away the current autosave and restore from the “backup” save, rewinding time to the start of the chapter.
Since most ChoiceScript games are a linear series of medium-sized chapters, this means that you’ll only lose your progress in chapter6.txt
, hopefully only fifteen or twenty minutes at most.
We only create a backup save if you’re not in a subscene
If you’re in chapter6.txt
, and you *gosub_scene subscene.txt
, we don’t set a backup at the start of subscene.txt
. We only set a backup at the start of a top-level scene.
During updates, the Titan Submersible Bug would rewind time all the way back to the chapter when you first called *gosub_scene
After the player trips over the Titan Submersible Bug, the player would never *return
from a subscene, so the backup save would never be created ever again for the rest of that playthrough. Whenever doing any future game updates, the player would have time rewinded back to the top of the chapter that first called *gosub_scene
and triggered the bug.
If you have the Titan Submersible Bug at the very start of the game, that would mean any mid-game updates would restart the entire game, defeating the purpose of our mid-game update system.
(This is exactly what happened to The Book of Hungry Names when we first launched it.)
We’ve implemented a workaround so the Titan Submersible Bug no longer blocks backup saves
Now, when you *goto_scene
after *gosub_scene
, we’ll treat the *goto_scene
scene as a “top-level scene”, not as a subscene.
Since that new behavior is quite confusing, we recommend (but don’t require) that authors fix their Titan Submersible Bugs in their own game.
Now, code with the Titan Submersible Bug will show a warning when you run RandomTest
The warning looks like this:
WARNING tools line 3: You should *return before *goto_scene after *gosub_scene from chapter3 line 63
When this happens, instead of using *goto_scene
in tools.txt
, you’ll need to update your code to use *return
instead, or to *goto_scene tools
instead of *gosub_scene tools
, if that’s what you intend to do.
It’s just a warning, not a failure, because many of our games have a Titan Submersible Bug, and it’s fine
Using RandomTest, I detected 26 published games that had the Titan Submersible Bug. (You can run RandomTest on your own game to find the bug and fix it.)
The Titan Submersible Bug is confusing, but it’s mostly harmless, and it’s usually pretty straightforward to fix it, now that the Titan Submersible Bug no longer breaks game updates.
So, we recommend (but don’t require) that authors fix their Titan Submersible Bugs in their own game by running RandomTest and addressing any warnings you find.