Skip to content

Latest commit

 

History

History
90 lines (73 loc) · 3.16 KB

File metadata and controls

90 lines (73 loc) · 3.16 KB

Enhanced Wrong Answer Feedback - Bug Fix

Problem

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.

Root Cause

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.

Solution

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:

  1. Always tries to call with enhanced options first
  2. Falls back gracefully if the interface doesn't support it
  3. Maintains backward compatibility with simpler interfaces

Files Changed

  • src/ChallengeProcessor.ts - Fixed both displayFailure and displaySuccess calls

Testing

All existing tests pass:

  • 28 tests in ChallengeProcessor.test.ts
  • Property tests verify that context is passed correctly ✓

Expected Behavior After Fix

When you get a question wrong, you should now see:

  1. Visual Effects:

    • Screen dims (colors desaturate and darken)
    • Flickering lantern effect
    • Shadow overlay creeping in from edges
  2. Audio Effects:

    • Whisper sounds (persona-specific)
    • Drumbeat sounds (persona-specific)
  3. Memory Fragment:

    • Persona-specific hint message displayed below the failure message
    • Styled differently from the main message
  4. Timing:

    • Effects last approximately 2-3 seconds
    • Effects restore smoothly in reverse order

How to Test

  1. Build the web version: npm run build:web
  2. Open dist-web/index.html in a browser
  3. Play through the game and intentionally answer a question wrong
  4. You should see all the enhanced feedback effects

Additional Notes

  • The enhanced feedback requires either a personaId or hint to be provided
  • If audio is muted, visual effects still play but audio is skipped
  • The implementation respects prefers-reduced-motion for accessibility
  • All CSS animations and styles were already in place - only the triggering logic needed fixing