即使我改变了一个变量,它仍然会恢复到它的旧值?

时间:2016-12-02 16:10:55

标签: batch-file variables math

我正在批量制作游戏,并且在故事开始时我让玩家失去5 HP,这取决于他们的选择。但是,在程序从原始HP(100)中减去5 HP之后,它会正确显示,但之后会恢复到100 HP,而不是95.

程序最顶端的变量

:: Stats
set Health=100
set Food=100
set Water=100
set Infection=100
set Stamina=100

播放器失去健康的代码(注意:使用95 HP正确调用的StatChange)

: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

变量返回100,即使我没有添加任何内容(退出之前的块)

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.

阻止显示统计信息的位置

: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

玩家失去5 HP,通常会打电话

http://imgur.com/a/1n8b2

左上角显示当前健康状况的“95”,在95 时正确调用

http://imgur.com/a/WoMyY

什么?!?!它回到了100!这就是我的问题所在。

http://imgur.com/a/ltRhY

0 个答案:

没有答案