Once again, I find myself facing a puzzling problem... Despite making progress in my game, revisiting one aspect reveals a quirk. There's a check to verify if the player possesses potions, and if so, attempts to use it involves calculating whether the resulting health exceeds the maximum limit. If it surpasses the cap, a refusal message appears; otherwise, the potion can be consumed. On the other hand, lacking any potions prompts a notification of unavailability.
The issue arises from the code executing twice unexpectedly. Here's an excerpt of the Switch Statement:
while (currentarea == "Hero's Turn") {
if (hTurn == true) {
switch (classType) {
case "Warrior":
case "Archer":
switch (input) {
case "punch":
case "p":
Punch();
break;
case "kick":
case "k":
Kick();
break;
case "attack":
case "a":
Attack();
break;
case "health potion":
case "h":
HealthPotion();
break;
default:
}
case "Mage":
switch (input) {
case "fire":
case "f":
FireMagic();
break;
case "wind":
case "w":
WindMagic();
break;
case "frost":
case "c":
IceMagic();
break;
case "health potion":
case "h":
HealthPotion();
break;
case "mana potion":
case "m":
ManaPotion();
break;
default:
}
default:
}
return;
}
}
Trying Archer on a separate line led to even more repetitions, indicating the trouble lies within Warrior and Archer cases where Mage behaved as intended with a single push of information.
Below is the function's code snippet:
function HealthPotion() {
// Function logic here...
}
This represents the potion object structure:
var healthPotion = {
Name: "Health Potion",
Health: 20,
AmountOf: 5,
Value: 30,
}
Here are the functions for checking enemy and hero status:
function checkE() {
// Enemy checking logic...
}
function checkH() {
// Hero checking logic...
}
Despite thorough examination, the issue remains elusive as complex switch statements and nested functions persist throughout the code. Testing across Firefox, Chrome, and Edge yield identical outcomes. Internet Explorer lacks compatibility due to incomplete coding integration.
Exploration of similar queries prior to seeking assistance revealed no parallels with this particular anomaly.
No errors were detected in any browser console; only recurring duplicated output was observed.
If persistent gameplay eventually necessitates potion usage after sustaining damage, the following outcome occurs: