Star Billions: Absolute Beginners

Update: With the release of Star Billions 2.0 in April 2016, the code behind Star Billions changed drastically. As a result, the information in this post should be considered out-of-date.

Q: How many programmers does it take to screw in a lightbulb?

A: Runtime Error. ?: in function <?:221>

I had programming experience before Star Billions, but most of it was with a statistical programming suite called SAS. I had never written anything in Lua before, but I knew the fundamentals from working on Yes, Chef! and some other pet projects in the past. I chose Corona SDK for Star Billions because my friend Blake had used it to make Rocket Valet and it seemed less intimidating than most other mobile game development platforms.

The internet is already full of Corona SDK resources, so any posts about programming on this blog are going to be about challenges specific to Star Billions. Today’s topic is the text engine that’s central to the Star Billions experience.

Each episode of Star Billions is stored in the JSON format. It looks something like this:

A peek into a Star Billions script

You’ll notice that each line of dialogue is surrounded by double-quotes and preceded by some text inside of [brackets] or {curly braces}. I’ll explain what happens with these lines one step at a time:

First, we search the line for text inside of brackets:
for fullCommand in string:gmatch("%[([^%[%]]*)%]") do

These are always “commands” that I’ve written in advance. For instance, the command rosie makes ROSIE appear and changes the dialogue to her signature red. Any commands in brackets are carried out right away. Commands in curly braces, on the other hand...
for fullCommand in string:gmatch("{([^{}]*)}") do

These are added to a “command queue” and carried out after the dialogue has been displayed. We use these commands for effects like flickering lights or expression changes.

Let’s look at an example of how commands are used to tell the AIs’ stories:
"[sarge][picture off]SARGE: Make us!", "[sarge 2][music stop][dark on]SARGE: . . .",

A short clip from the first season of Star Billions

Voila! With just a few keystrokes, the lights go out on the Little Brother and SARGE tucks his tail between his legs. Simple scripting languages like this are the backbone of many story-centric games, from EarthBound to The Walking Dead. These games may look worlds apart on the surface, but they’re governed by the same underlying principles.

The text engine is just one of fifteen modules I made to tell our story. Stay tuned for more behind-the-scenes looks at the code behind Star Billions.