« get me outta code hell

Don't crash when option index is out of bounds - csb-game - Pixelly spin-off of the Command Synergy Battle system used in Final Fantasy XIII
summary refs log tree commit diff
path: root/index.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-08-16 09:23:17 -0300
committerFlorrie <towerofnix@gmail.com>2018-08-16 09:23:17 -0300
commit24a30325f5129a07d2030ac8501782c25576484a (patch)
tree3a2146f71391b60b844a3278c9d8f1ff876f7210 /index.js
parent841b9d8f83bda72ddd8326b77e3696ca1ca24812 (diff)
Don't crash when option index is out of bounds
Diffstat (limited to 'index.js')
-rw-r--r--index.js7
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]
   }