From 619365344f09304ab6c4bc145c7721d91123388a Mon Sep 17 00:00:00 2001 From: raeleus Date: Mon, 7 Oct 2024 05:52:58 -0700 Subject: [PATCH] Added error checking to #initiative. --- Input.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Input.js b/Input.js index f8fecd1..4e09b6a 100644 --- a/Input.js +++ b/Input.js @@ -1708,16 +1708,28 @@ function doAddEnemy(command) { } function doInitiative(command) { - for (character of state.characters) { + var battleHasStarted = state.initiativeOrder.length != 0 + + if (!battleHasStarted) for (character of state.characters) { var stat = character.stats.find(element => element.name.toLowerCase() == "dexterity") if (stat == null) character.initiative = calculateRoll("d20") else character.initiative = calculateRoll("d20") + getModifier(stat.value) } - createInitiativeOrder() + if (state.enemies.length == 0) { + state.show = "none" + return "\n[Error: No enemies! Call #addenemy or #generateencounter]\n" + } + + if (!battleHasStarted) createInitiativeOrder() + + if (state.initiativeOrder.length == 0) { + state.show = "none" + return "\n[Error: No combatants! Ensure that your characters have health and you have added enemies. See #help]\n" + } state.show = "initiative" - return "\nBattle has commenced!\n" + return battleHasStarted ? " " : "\nBattle has commenced!\n" } function doTake(command) {