diff options
author | Florrie <towerofnix@gmail.com> | 2018-08-16 09:23:17 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-08-16 09:23:17 -0300 |
commit | 24a30325f5129a07d2030ac8501782c25576484a (patch) | |
tree | 3a2146f71391b60b844a3278c9d8f1ff876f7210 | |
parent | 841b9d8f83bda72ddd8326b77e3696ca1ca24812 (diff) |
Don't crash when option index is out of bounds
-rw-r--r-- | index.js | 7 |
1 files changed, 7 insertions, 0 deletions
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] } |