← Back to the gamebug or idea?Terrapin Trail//Code BibleIIhow the game works, archive to van
Reel 04 · 6 min read

Lists of stuff the game reads

What an 'array' and an 'object' are, and why almost everything in the game is just a list the code loops over.

Every role you can play, every item on Shakedown Street, every random road event — where does all that "stuff" live? Not scattered through the code. It's kept in neat lists near the top of the file, and the game reads those lists to run. This is one of the most useful patterns in all of programming.

Concept: an "array" (a list). An array is an ordered list of things: [2, 4, 6], or a shopping list. The game keeps its road events in one big array, its items in another, and so on.

Concept: an "object". An object is a labelled bundle of facts about one thing — like an index card. A van part might be { name: "Aux Fuel Tank", price: 16 }: a name label with a value, a price label with a value. The game's lists are lists of these cards.

A catalog is a list of cards

Here's the "mods" list — the perks you can pick when building your character. Each entry is a card with a name, a description, and a small instruction for what it does:

●assets/game/game.js : 1033–1041trace ↗
1033  var MODS = [
1034    { id: "iron_stomach", name: "Iron Stomach", desc: "Bad clams, cursed burritos -- nothing touches you.", apply: function (s) { s.flags.ironStomach = true; } },
1035    { id: "silver_tongue", name: "Silver Tongue", desc: "You talk your way in anywhere. +12 starting Lot Cred.", apply: function (s) { s.cred = clamp(s.cred + 12, 0, 100); } },
1036    { id: "lead_foot", name: "Lead Foot", desc: "You drive like you're being chased. Legs go faster; the van pays for it.", apply: function (s) { s.flags.leadFoot = true; } },
1037    { id: "night_owl", name: "Night Owl", desc: "Your best thinking happens at 3 a.m. Your Peak hits even harder.", apply: function (s) { s.flags.nightOwl = true; } },
1038    { id: "golden_ears", name: "Golden Ears", desc: "You hear the whole mix. +8 quality on every tape you pull.", apply: function (s) { s.flags.goldenEars = true; } },
1039    { id: "pack_rat", name: "Pack Rat", desc: "You start with a random extra piece of van gear in your stash.", apply: function (s) { s.flags.packRat = true; } },
1040    { id: "been_there", name: "Been There", desc: "Whatever's in the snack, you've had worse. Immune to bad trips.", apply: function (s) { s.doseImmune = true; } },
1041    { id: "grease_monkey", name: "Grease Monkey", desc: "You keep the bus alive with spit and wire. Van starts +15.", apply: function (s) { s.van = clamp(s.van + 15, 0, 100); } },
Each line is one perk: a name, a description, and a little recipe (apply) for how it changes your character.

You don't need to follow the recipe part in detail. The point is the shape: every perk is the same kind of card, so the game can handle them all with one piece of code. To add a new perk, you add a new card — you don't write new machinery.

Why this is such a big deal

Concept: "data-driven". When a program's behavior comes from lists of data it reads (rather than from special code written for each case), we call it data-driven. It means adding content is like adding a row to a spreadsheet, not rewiring the machine.

The whole game works this way. Roles, tours, crew members, shop items, road events, achievements — all lists of cards. And the game's engine is written to read any card of the right shape, so:

  • Adding a new road event is adding one card to the events list.
  • Adding a new shop item, one card to the items list.
  • The person adding content never has to touch the tricky engine code.

This is why a small team can pack so much variety into one file: the hard part (the engine) is written once, and the content is just data poured into it.

The ideas to keep
  • An array is a list; an object is a labelled bundle of facts (an index card).
  • The game's content is lists of cards — roles, items, events — all near the top of the file.
  • Data-driven means adding content is adding a card, not rewriting the engine.