Spielerando

The Achievement Pop-Up Tells the Same Unlocks Twice

When many achievements unlock at once, games show one pop-up at a time and fold the rest into a summary such as "and 3 more". If a later summary counts unlocks the player has already been told about, the count of the earlier summary was not cleared when it ended. TLC found this in our own achievements blueprint, and Lean replayed the case: six unlocks told to the player as nine.

What you see

Why does the summary count them again?

Our achievements blueprint keeps a short line of pop-ups and counts whatever does not fit for a summary. When the summary had run its time while a pop-up was still waiting in the line, the code brought up that pop-up and kept the summary's count. The next summary then started from the old count and added the new unlocks to it, so the ones already told were told again.

TLC found it while checking the rule that every unlock is told exactly once: a path through six states on which the same unlock was set to be told a second time. Lean then replayed the busy moment with the old code: four unlocks at once into a line of one, two more while the summary shows, and nine announced for six unlocks.

How to check your game for it

The code below keeps a count of what the player has been told, only for the check. The first test plays Lean's busy moment and asks for six told. The second plays every order of up to ten unlocks and pop-ups running out, with a line of one and of two, lets everything run out, and asks that the count told equals the count unlocked. That is the rule TLC checked, as a plain loop. On the old code it stops at the first order that breaks it, which is shorter than Lean's.

The test: fix.test.ts

TypeScript for Node's own test runner. The tests named below as the catch are the ones that fail on the bug.

import assert from "node:assert/strict";
import test from "node:test";
import { ended, nothing, type Popups, unlock } from "./fix.ts";

/** Plays a list of events ("u" an unlock, "e" the pop-up on screen ends), then lets every pop-up
    left run out. Returns how many unlocks there were and how many the player was told about. */
function play(events: string, lineLimit: number): { unlocked: number; told: number } {
  let p: Popups = nothing;
  let unlocked = 0;
  for (const event of events) {
    if (event === "u") p = unlock(p, `goal ${++unlocked}`, lineLimit);
    else p = ended(p);
  }
  while (p.showing !== null) p = ended(p);
  return { unlocked, told: p.told };
}

test("six unlocks are told as six", () => {
  // four at once into a line of one, two pop-ups end, two more while the summary shows
  assert.deepEqual(play("uuuueeuu", 1), { unlocked: 6, told: 6 });
});

test("in every order of up to ten unlocks and ends, each unlock is told once", () => {
  for (const lineLimit of [1, 2]) {
    for (let length = 1; length <= 10; length++) {
      for (let bits = 0; bits < 2 ** length; bits++) {
        const events = [...Array(length)].map((_, i) => ((bits >> i) & 1 ? "u" : "e")).join("");
        const { unlocked, told } = play(events, lineLimit);
        assert.equal(told, unlocked, `"${events}" with a line of ${lineLimit}: ${unlocked} unlocks told as ${told}`);
      }
    }
  }
});

test("a single unlock shows on its own", () => {
  const p = unlock(nothing, "first jump", 1);
  assert.equal(p.showing, "first jump");
  assert.equal(ended(p).showing, null);
});

The catch:

What it said on the code with the bug put back

✖ six unlocks are told as six
    got { unlocked: 6, told: 9 }, expected { unlocked: 6, told: 6 }
✖ in every order of up to ten unlocks and ends, each unlock is told once
    "uuueeu" with a line of 1: 4 unlocks told as 5
    got 5, expected 4
✔ a single unlock shows on its own
3 tests: 1 passed, 2 failed

What it said on the fixed code

✔ six unlocks are told as six
✔ in every order of up to ten unlocks and ends, each unlock is told once
✔ a single unlock shows on its own
3 tests: 3 passed, 0 failed

Run by pnpm fixes:check on 2026-11-26 with Node v24.15.0. The text above is its output.

The fix

When a summary ends, it has told everything it held, including the unlocks folded into it while it was on screen. So its count goes back to zero, whatever comes next. The two changed lines are below: the count goes when a summary ends, and so a summary that has just ended no longer needs its own guard against coming back.

What changed

Lines with - are the code with the bug, lines with + the fix.

    if (p.showing === null) return p;
    const told = p.told + (p.showing === MORE ? p.more : 0);
-   const more = p.more;
+   // A summary that ends has told all it held, so its count goes.
+   const more = p.showing === MORE ? 0 : p.more;
    if (p.line.length > 0) return { showing: p.line[0], line: p.line.slice(1), more, told: told + 1 };
-   if (more > 0 && p.showing !== MORE) return { showing: MORE, line: [], more, told };
+   if (more > 0) return { showing: MORE, line: [], more, told };
    return { showing: null, line: [], more: 0, told };
  }

The fixed code: fix.ts

/* Pop-ups for unlocked achievements: one on screen, a short line behind it, and whatever does not fit
   folded into one summary ("and 3 more"). A summary that ends has told everything it held, also
   what was folded in while it showed. From the achievements blueprint:
   https://spielerando.com/en/mechanics/achievements */

export const MORE = "more";

export interface Popups {
  /** On screen: an achievement, MORE for the summary, or null. */
  showing: string | null;
  /** Waiting behind it. */
  line: string[];
  /** Unlocks folded into the summary. */
  more: number;
  /** For the check: unlocks the player has been told about so far. */
  told: number;
}

export const nothing: Popups = { showing: null, line: [], more: 0, told: 0 };

/** A new unlock: on screen if nothing is, else in the line while it has room, else into the summary. */
export function unlock(p: Popups, id: string, lineLimit: number): Popups {
  if (p.showing === null) return { ...p, showing: id, told: p.told + 1 };
  if (p.line.length < lineLimit) return { ...p, line: [...p.line, id] };
  return { ...p, more: p.more + 1 };
}

/** The pop-up on screen has had its time. The next in line comes up, then the summary. */
export function ended(p: Popups): Popups {
  if (p.showing === null) return p;
  const told = p.told + (p.showing === MORE ? p.more : 0);
  // A summary that ends has told all it held, so its count goes.
  const more = p.showing === MORE ? 0 : p.more;
  if (p.line.length > 0) return { showing: p.line[0], line: p.line.slice(1), more, told: told + 1 };
  if (more > 0) return { showing: MORE, line: [], more, told };
  return { showing: null, line: [], more: 0, told };
}

Paste this to your AI

In my game, when many achievements unlock at once, a summary pop-up ("and 3 more") counts unlocks the player was already told about. I think a summary keeps its count after it ends, so the next summary starts from it.

1. Before you change anything, write down the states of my pop-ups: nothing on screen, one pop-up, a line waiting, a summary on screen. Write down what each event (a new unlock, a pop-up running out) does to the line and to the summary's count. Next to it write the rule: once everything has run out, the player has been told about every unlock exactly once.
2. Write tests like the ones below for my code: the case of six unlocks, and a loop over every order of up to ten unlocks and pop-ups running out, that checks the rule. Run them and paste me the real output.
3. If they fail, fix it the way the code below does: when a summary ends, its count goes, because it has told everything it held. Run the tests again and paste the output.
4. Let the summary keep its count again for a moment, show me the tests failing, and undo it.

Do not tell me it is fixed unless the test output shows it.

The button copies this text together with the fixed code and the test above, so your AI has everything.

Where we found it

The blueprint the bug was in, and the test that guards it there:

How we found them: the bugs our proofs found in our own code

Was this page helpful?

One click, no account. It shows us which pages help.

Next step

Fix by symptom

The Quest Is Done Before the Player Did Anything

A quest that counts as done the moment it starts usually has an empty list of goals: "every goal is met" says yes to an empty list. The test and the fix.

Last updated: 2026-11-26