From 4c5043378f584d83941d2c6b7c9295d02154af30 Mon Sep 17 00:00:00 2001 From: hexagonhexagon Date: Sun, 28 Jun 2020 01:18:49 -0400 Subject: [PATCH] Fix issue where pressing B just after loading crashes the game. --- src/js/game/hub_goals.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/js/game/hub_goals.js b/src/js/game/hub_goals.js index 3f4f1cf3..67966384 100644 --- a/src/js/game/hub_goals.js +++ b/src/js/game/hub_goals.js @@ -106,13 +106,14 @@ export class HubGoals extends BasicSerializableObject { // Allow quickly switching goals in dev mode if (G_IS_DEV) { - if (G_IS_DEV) { - window.addEventListener("keydown", ev => { - if (ev.key === "b") { + window.addEventListener("keydown", ev => { + if (ev.key === "b") { + // root is not guaranteed to exist within ~0.5s after loading in + if (this.root && this.root.app && this.root.app.gameAnalytics) { this.onGoalCompleted(); } - }); - } + } + }); } }