Doss Academy
Skip to learning content

Lesson Notes — Your First Mod: Tuning Knobs in One Life

Course 2: Game Design & Development Principles / Unit 6: Game Design Mechanics, Rules & Documentation / Lesson 6: Your First Mod: Tuning Knobs in One Life

The golden rule: You only work inside your own folder in the expansions folder. You never edit index.html or any other game file. If your expansion breaks, you delete your folder and the game is exactly as it was.

Lesson overview

An expansion (also called a mod) is a separate folder of code that changes a game without rewriting the game. One Life loads expansion folders from its expansions folder, so you can change how it plays without touching the game itself. Today you start from the expansion template, make your own copy, load it, and change how many points an interaction is worth. Designers call a number like this a tuning knob, because you turn it up or down to change how the game feels.

The folder

Unzip One Life version 153 or newer. Inside you will find an expansions folder:

One_Life/
  index.html                (the game: do not edit)
  expansions.js             (the game's own file: do not edit)
  expansions/               (the only folder you work in)
    _template/              (the template: copy this whole folder, do not edit it)
      expansion.js
    loader.js               (loads expansion folders: do not edit)
    manifest.js             (the list of folders to load)
    README.txt
    Popularity_Boost/                  (YOUR expansion: a folder you make by copying _template)
      expansion.js

The file expansions.js next to index.html belongs to the game. Do not confuse it with the expansions folder, which belongs to you.

Each expansion is its own folder inside expansions, with a file named expansion.js inside it. Many expansion folders can be loaded at the same time. On the class website, every folder in expansions loads automatically. A saved copy on your own device cannot look inside folders, so there you also list your folder name in manifest.js (Step 4).

Step 1: Copy the template

  1. Open the expansions folder.
  2. Copy the whole _template folder and rename the copy with the title of your expansion, with no spaces (letters, numbers, – or _ only), like Popularity_Boost. Do not use your own name. Keep the file inside named expansion.js.
  3. Open Popularity_Boost/expansion.js in a text editor (Notepad, TextEdit, or VS Code).

Step 2: Read the template

This is the whole template:

// =====================================================
// One Life expansion template
// 1. Copy this whole _template folder into the expansions folder and rename the copy
//    (for example: Popularity_Boost, the title of your expansion). The file inside must stay named expansion.js.
// 2. Edit expansion.js in YOUR folder. Leave _template alone.
// 3. Add your folder name to expansions/manifest.js.
// Do not edit index.html.
//
// Name:          (your expansion's name)
// Version:       1.0
// Tested on:     One Life version (number)
// What it does:  (one sentence)
// To turn off:   remove your folder name from expansions/manifest.js, or delete your folder
// =====================================================
(function () {
  'use strict';

  const NAME = 'My Expansion';   // change this to your expansion's name

  if (typeof likePoints === 'undefined') {
    console.warn(NAME + ': the game is not ready, so this expansion did not run.');
    return;
  }

  // ---- PART 1: TUNING KNOBS (change values) ----
  const knobs = {
    // kept: 6,      // was 4
    // noShow: -8,   // was -5
  };
  for (const [kind, value] of Object.entries(knobs)) {
    if (kind in likePoints) likePoints[kind] = value;
    else console.warn(NAME + ': unknown interaction "' + kind + '"');
  }

  // ---- PART 2: RULES (replace a formula) -- optional ----
  // friendLimit = function () {
  //   return Math.floor(popularityScore() / 8);   // was 10
  // };

  // ---- PART 3: EVENT LOGGER -- optional ----
  // const originalRecord = recordContactEvent;
  // recordContactEvent = function (id, kind, key) {
  //   const before = popularityScore();
  //   const result = originalRecord(id, kind, key);
  //   console.log(kind + ' with ' + id + ': popularity ' + before + ' -> ' + popularityScore());
  //   return result;
  // };

  console.log('Expansion loaded: ' + NAME);
})();

How the template works

  • The header is a comment. It tells anyone who opens your file what it is and how to turn it off.
  • The wrapper (function () { ... })(); gives your code its own scope: a private space. Variables you create inside it cannot clash with the game or with a classmate’s expansion that uses the same names.
  • The safety check stops the expansion cleanly if the game is not ready.
  • Part 1 changes values. likePoints is an object: a list of names with a number for each. The game looks up the number each time something happens, so changing the number changes the game. The loop checks each name really exists, and warns you if you mistype one.
  • Part 2 replaces formulas (Lesson 7).
  • Part 3 logs what each interaction is worth (Lesson 8).
  • A line that starts with // is a comment and does nothing. Remove the // to turn a line on.

Step 3: Edit your copy

  1. Fill in the header and change NAME.
  2. In Part 1, remove the // from the two example lines and choose your own values. You can use any interaction name from the table in Lesson 5. Type likePoints in the Console to see the full list. The Names Reference in Lesson 4 lists every other name in the game that you can read or change.
  3. Save the file.

Step 4: Add your folder to the manifest

The manifest is the list of folders the game should load. Open expansions/manifest.js and add your folder name:

window.oneLifeExpansionFolders = [
  'Popularity_Boost',
];

The game loads the folders in the order they are listed, so if two expansions change the same thing, the one listed last wins. To load a classmate’s expansion too, put their folder in expansions and add their name to the list. To turn an expansion off, put // in front of its name, or delete its folder.

Step 5: Check that it worked

  1. Reload index.html in your browser.
  2. Press F12 and click Console. You should see Expansion loaded: followed by your name.
  3. Type likePoints.kept and press Enter. It should show your value.

Things to know

  • Start a new game to test cleanly. A saved game already has points recorded under the old values. Your expansion changes what future events are worth.
  • Reload the page after every change to your file.
  • Change one thing at a time so you know what caused what.

Common errors

What you see in the Console Likely cause
Nothing about your expansion Your folder name is not in manifest.js, or it still has // in front of it.
could not load expansions/Popularity_Boost/expansion.js The name in manifest.js does not match the folder name exactly, or the folder has no file named expansion.js inside it.
skipped: Use a plain folder name The manifest has a path like ../ or a name with spaces or symbols.
no expansions loaded. Browsers cannot list folders You are on a saved copy and the manifest list is empty. Add your folder name (Step 4).
unknown interaction You mistyped an interaction name in Part 1.
Unexpected token or Unexpected identifier (red) A missing comma, bracket, or quote in your file. The message gives the file and line number.

Your turn

  1. Complete the setup checklist on your handout.
  2. Choose two interactions. Before you change them, write a prediction about how the game will feel different.
  3. Change them, reload, start a new game, and play for five minutes.
  4. Write what actually happened and whether your prediction was right.

Check your understanding

  1. Why do expansions live in their own folder instead of inside the game?
  2. What does the wrapper (function () { ... })(); protect you from?
  3. What is a tuning knob? Name one in One Life.

Use this lesson’s Key Terms page to build your glossary.

Discuss and submit in Google Classroom

Use this site to read, watch, and get shared learning materials. Keep completed work, questions, and comments in your class on Google Classroom.

Open Google Classroom

Choose your class and the assignment named by your teacher.