Das Erfolgs-Pop-up meldet dieselben Erfolge zweimal
Werden viele Erfolge auf einmal freigeschaltet, zeigen Spiele ein Pop-up nach dem anderen und fassen den Rest in einem Sammel-Pop-up zusammen, etwa "und 3 weitere". Zählt ein späteres Sammel-Pop-up Erfolge mit, die schon gemeldet waren, dann wurde die Zahl des früheren nicht gelöscht, als es endete. TLC hat das in unserem eigenen Erfolge-Bauplan gefunden, und Lean hat den Fall nachgespielt: sechs Erfolge, dem Spieler als neun gemeldet.
Was du siehst
- Eine Welle von Erfolgen, ein erstes Sammel-Pop-up und dann ein zweites, dessen Zahl Erfolge enthält, die das erste schon abgedeckt hat.
- Es braucht einen vollen Moment: mehrere Erfolge auf einmal und weitere, während das Sammel-Pop-up zu sehen ist.
- Die Liste der freigeschalteten Erfolge bleibt richtig. Nur was dem Spieler gemeldet wird, ist falsch, deshalb tut man es leicht ab.
Warum zählt das Sammel-Pop-up sie noch einmal?
Unser Bauplan Erfolge hält eine kurze Reihe von Pop-ups und zählt, was nicht hineinpasst, für ein Sammel-Pop-up. War das Sammel-Pop-up abgelaufen, während noch ein Pop-up in der Reihe wartete, holte der Code dieses Pop-up nach vorn und behielt die Zahl des Sammel-Pop-ups. Das nächste Sammel-Pop-up fing dann bei der alten Zahl an und zählte die neuen Erfolge dazu, also wurden die schon gemeldeten noch einmal gemeldet.
TLC fand es beim Prüfen der Regel, dass jeder Erfolg genau einmal gemeldet wird: einen Weg über sechs Zustände, auf dem derselbe Erfolg ein zweites Mal gemeldet werden sollte. Lean spielte dann den vollen Moment mit dem alten Code nach: vier Erfolge auf einmal in eine Reihe von einem, zwei weitere, während das Sammel-Pop-up zu sehen ist, und neun Meldungen für sechs Erfolge.
So prüfst du dein Spiel darauf
Der Code unten zählt mit, was dem Spieler gemeldet wurde, nur für die Prüfung. Der erste Test spielt Leans vollen Moment und verlangt sechs Meldungen. Der zweite spielt jede Reihenfolge von bis zu zehn Erfolgen und ablaufenden Pop-ups, mit einer Reihe von einem und von zwei, lässt alles ablaufen und verlangt, dass die Zahl der Meldungen die Zahl der Erfolge ist. Das ist die Regel, die TLC geprüft hat, als einfache Schleife. Beim alten Code hält sie bei der ersten Reihenfolge an, die die Regel bricht, und die ist kürzer als die von Lean.
Der Test: fix.test.ts
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);
});
Der Fang:
- six unlocks are told as six
- in every order of up to ten unlocks and ends, each unlock is told once
Was er beim Code mit dem wieder eingebauten Fehler sagte
✖ 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 failedWas er beim behobenen Code sagte
✔ 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 failedDie Lösung
Wenn ein Sammel-Pop-up endet, hat es alles gemeldet, was es enthielt, auch die Erfolge, die dazukamen, während es zu sehen war. Also geht seine Zahl auf null zurück, egal was danach kommt. Die zwei geänderten Zeilen stehen unten: Die Zahl verfällt, wenn ein Sammel-Pop-up endet, und deshalb braucht ein gerade beendetes Sammel-Pop-up keine eigene Sperre mehr gegen seine Rückkehr.
Was sich geändert hat
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 };
}Der behobene 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 };
}
Das gibst du deiner KI
Wenn in meinem Spiel viele Erfolge auf einmal freigeschaltet werden, zählt ein Sammel-Pop-up ("und 3 weitere") Erfolge mit, die dem Spieler schon gemeldet wurden. Ich vermute, ein Sammel-Pop-up behält seine Zahl nach seinem Ende, und das nächste fängt damit an.
1. Bevor du etwas änderst, schreib die Zustände meiner Pop-ups auf: nichts zu sehen, ein Pop-up, eine wartende Reihe, ein Sammel-Pop-up zu sehen. Schreib auf, was jedes Ereignis (ein neuer Erfolg, ein Pop-up läuft ab) mit der Reihe und mit der Zahl des Sammel-Pop-ups macht. Schreib die Regel dazu: Wenn alles abgelaufen ist, wurde jeder Erfolg genau einmal gemeldet.
2. Schreib für meinen Code Tests wie die unten: den Fall mit sechs Erfolgen und eine Schleife über jede Reihenfolge von bis zu zehn Erfolgen und ablaufenden Pop-ups, die die Regel prüft. Lass sie laufen und füg mir die echte Ausgabe ein.
3. Schlagen sie fehl, behebe es wie der Code unten: Wenn ein Sammel-Pop-up endet, verfällt seine Zahl, weil es alles gemeldet hat, was es enthielt. Lass die Tests noch einmal laufen und füg die Ausgabe ein.
4. Lass das Sammel-Pop-up seine Zahl kurz wieder behalten, zeig mir die fehlschlagenden Tests und mach es rückgängig.
Sag mir nicht, es sei behoben, wenn die Ausgabe der Tests das nicht zeigt.
Der Code, von https://spielerando.com/de/fixes/achievement-pop-up-tells-unlocks-twice (TypeScript, tested):
```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 };
}
```
Der Test, der es findet:
```ts
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);
});
```
Wenn in meinem Spiel viele Erfolge auf einmal freigeschaltet werden, zählt ein Sammel-Pop-up ("und 3 weitere") Erfolge mit, die dem Spieler schon gemeldet wurden. Ich vermute, ein Sammel-Pop-up behält seine Zahl nach seinem Ende, und das nächste fängt damit an.
1. Bevor du etwas änderst, schreib die Zustände meiner Pop-ups auf: nichts zu sehen, ein Pop-up, eine wartende Reihe, ein Sammel-Pop-up zu sehen. Schreib auf, was jedes Ereignis (ein neuer Erfolg, ein Pop-up läuft ab) mit der Reihe und mit der Zahl des Sammel-Pop-ups macht. Schreib die Regel dazu: Wenn alles abgelaufen ist, wurde jeder Erfolg genau einmal gemeldet.
2. Schreib für meinen Code Tests wie die unten: den Fall mit sechs Erfolgen und eine Schleife über jede Reihenfolge von bis zu zehn Erfolgen und ablaufenden Pop-ups, die die Regel prüft. Lass sie laufen und füg mir die echte Ausgabe ein.
3. Schlagen sie fehl, behebe es wie der Code unten: Wenn ein Sammel-Pop-up endet, verfällt seine Zahl, weil es alles gemeldet hat, was es enthielt. Lass die Tests noch einmal laufen und füg die Ausgabe ein.
4. Lass das Sammel-Pop-up seine Zahl kurz wieder behalten, zeig mir die fehlschlagenden Tests und mach es rückgängig.
Sag mir nicht, es sei behoben, wenn die Ausgabe der Tests das nicht zeigt.Wo wir es gefunden haben
Der Bauplan, in dem der Fehler steckte, und der Test, der ihn dort bewacht:
- Erfolge:
a-summary-tells-each-unlock-once
Wie wir sie gefunden haben: die Fehler, die unsere Beweise in unserem eigenen Code fanden