I'm making a game in batch, and I have the player lose 5 HP in the beginning of the story, depending on their choices. However, after the program subtracts 5 HP from the original HP (100), it displays correctly, but then it reverts back to 100 HP, instead of 95.
Variables at the very top of the program
:: Stats
set Health=100
set Food=100
set Water=100
set Infection=100
set Stamina=100
Code where the player loses health (Note :StatChange, that calls correctly with 95 HP)
:Beans
setlocal disableDelayedExpansion
call :colorEcho2 7 "Finally deciding that you're going to have Canned Beans for breakfast, you grab a knife from the kitchen counter and work the top off. While eating the beans straight from the can, you cut your lip! It starts to bleed."
Echo .
set /a Health=Health-5
Echo.
call :colorEcho2 C "# ALERT; You have lost 5 Health Points! You are now at %Health% HP!"
setlocal enableDelayedExpansion
Echo.
Echo.
pause
cls
call :StatChange
Echo.
call :colorEcho 7 "You quickly grab a rag and hold it to your lip, stopping the bleeding. The can didn't cut very deep, so it should heal quickly. Once your lip has stopped bleeding, you carefully finish your breakfast, and drink some water."
call :colorEcho 7 "You decide the knife would be useful, so you stuff it in your Daypack that you grabbed from your bedside table."
setlocal disableDelayedExpansion
Echo.
Echo.
call :colorEcho2 E "Acquried Knife! +2 Damage to Zombies!"
setlocal enableDelayedExpansion
set Weapon="Knife"
Echo.
Echo.
call :colorEcho 7 "You look towards your cupboard, and see the Bacon still lying there. You contemplate on whether or not you should take it with you."
Echo.
Echo.
Echo Are you going to take the Bacon with you?
Echo Your options are:
call :colorEcho C "================="
Echo.
Echo 1. Ew, no way^^^!
Echo 2. Sure, why not? More food means better chance of survival.
call :colorEcho C "================="
Echo.
Echo Please enter the number corresponding to your answer.
set /p Answer4="Enter your choice: "
Echo.
setlocal disableDelayedExpansion
if "%Answer4%"=="1" call :colorEcho2 7 "You decide not to take the Bacon!"
setlocal enableDelayedExpansion
Echo.
if "%Answer4%"=="2" (
call :colorEcho 7 "You stuff the Bacon into your backpack."
Echo.
Echo.
setlocal disableDelayedExpansion
call :colorEcho2 E "Acquired Bacon!"
setlocal enableDelayedExpansion
set /a Bacon+=1
Echo.
Echo.
)
pause
exit /b
Where the variable goes back to 100, even though I did not add anything (The block before exits to here)
cls
call :StatChange
Echo.
Echo.
call :colorEcho 7 "You walk into your storage room. You see lots of crates, some filled to the top with items. You look around, wondering what to take."
Echo .
call :colorEcho 7 "You see a med pack, an MRE, some tablets, an Adrenaline syringe, a grenade, and a flare."
call :colorEcho 7 ". You look at your backpack, and you realize that you may not have enough space in the future if you take everything. You decide to take only 2 items."
Echo .
Echo.
Block where the stats are displayed
:StatChange
call :colorEcho A "Current Health = "
call :colorEcho C " %Health%"
Echo.
call :colorEcho A "Hunger = "
call :colorEcho C " %Food%"
Echo.
call :colorEcho A "Thirst = "
call :colorEcho C " %Water%"
Echo.
call :colorEcho A "Infection = "
call :colorEcho C " %Infection%"
Echo.
call :colorEcho A "Stamina = "
call :colorEcho C " %Stamina%"
Echo.
exit /b
Player loses 5 HP, calls normally
https://i.stack.imgur.com/L4vLG.jpg
At the top left, shown '95' for current health, is called correctly at 95
https://i.stack.imgur.com/v9Fba.jpg
What?!?! It went back to 100! That's where my problem is.