From 24a30325f5129a07d2030ac8501782c25576484a Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 16 Aug 2018 09:23:17 -0300 Subject: Don't crash when option index is out of bounds --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index c7327d6..00b35b8 100644 --- a/index.js +++ b/index.js @@ -336,6 +336,8 @@ class BaseBattleMenu { return } + this.keepCurrentIndexInBounds() + this.drawY = 1 if (this.options.length > 3) { @@ -375,7 +377,12 @@ class BaseBattleMenu { return this.canvas.width - 2 } + keepCurrentIndexInBounds() { + this.currentOptionIndex = Math.min(this.options.length - 1, this.currentOptionIndex) + } + getCurrentOption() { + this.keepCurrentIndexInBounds() return this.options[this.currentOptionIndex] } -- cgit 1.3.0-6-gf8a5