When getting a question wrong in the game, the enhanced visual and audio feedback effects (dimming, flickering, shadow overlay, whispers, drumbeats, and memory fragments) were not being triggered. Only the simple popup message was displayed.
The issue was in src/ChallengeProcessor.ts in the displayQuestionFeedback() method. The code was checking the function length to determine if the displayFailure method supported the enhanced feedback options:
if (displayFailureMethod.length >= 3) {
// Call with enhanced options
}However, JavaScript's Function.length property only counts parameters before the first one with a default value. The displayFailure signature is:
async displayFailure(
message: string, // param 1 - counted
autoTransitionMs: number = 2000, // param 2 - has default, NOT counted
options?: { ... } // param 3 - NOT counted
)So displayFailure.length returns 1, not 3, causing the check to fail and fall back to the simple version without enhanced feedback.
Changed the detection logic from checking function length to using a try-catch approach:
try {
// Attempt to call with enhanced feedback options (WebPlayerInterface)
await (playerInterface as any).displayFailure(
question.failure_message,
2000,
{
personaId,
hint,
attemptNumber
}
);
} catch (error) {
// Fallback for interfaces that don't support options
await playerInterface.displayFailure(question.failure_message);
}This approach:
- Always tries to call with enhanced options first
- Falls back gracefully if the interface doesn't support it
- Maintains backward compatibility with simpler interfaces
src/ChallengeProcessor.ts- Fixed bothdisplayFailureanddisplaySuccesscalls
All existing tests pass:
- 28 tests in
ChallengeProcessor.test.ts✓ - Property tests verify that context is passed correctly ✓
When you get a question wrong, you should now see:
-
Visual Effects:
- Screen dims (colors desaturate and darken)
- Flickering lantern effect
- Shadow overlay creeping in from edges
-
Audio Effects:
- Whisper sounds (persona-specific)
- Drumbeat sounds (persona-specific)
-
Memory Fragment:
- Persona-specific hint message displayed below the failure message
- Styled differently from the main message
-
Timing:
- Effects last approximately 2-3 seconds
- Effects restore smoothly in reverse order
- Build the web version:
npm run build:web - Open
dist-web/index.htmlin a browser - Play through the game and intentionally answer a question wrong
- You should see all the enhanced feedback effects
- The enhanced feedback requires either a
personaIdorhintto be provided - If audio is muted, visual effects still play but audio is skipped
- The implementation respects
prefers-reduced-motionfor accessibility - All CSS animations and styles were already in place - only the triggering logic needed fixing