From 62f96562f15908cf05bb192a4867a8d00a741189 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sat, 18 Apr 2020 20:46:35 -0400 Subject: [PATCH] Actually fix NPE in footsteps --- docs/assets/js/sounds/sounds.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/assets/js/sounds/sounds.js b/docs/assets/js/sounds/sounds.js index 85a0583..f513783 100644 --- a/docs/assets/js/sounds/sounds.js +++ b/docs/assets/js/sounds/sounds.js @@ -37,8 +37,14 @@ let soundAssets = { */ function playRandomFootstep() { - // There has to be a one-liner somewhere in the game... - [soundAssets.footstep1, soundAssets.footstep2, soundAssets.footstep3, soundAssets.footstep4, soundAssets.footstep5, soundAssets.footstep6][Math.min(Math.floor(Math.random() * Object.keys(soundAssets).length - 1), Object.keys(soundAssets).length - 1)].play(); + // Build a list of footsteps + let step_sounds = [soundAssets.footstep1, soundAssets.footstep2, soundAssets.footstep3, soundAssets.footstep4, soundAssets.footstep5, soundAssets.footstep6]; + + // Choose a random footstep + let footstep_id = Math.floor(Math.random() * step_sounds.length); + + // Play the sound + step_sounds[footstep_id].play(); } /**