所以,我正在使用批量编码制作游戏,而且我在游戏中有一个商店,它只能销售每个商品中的一个。不幸的是,当我将项目的变量设置为1,然后将其减少为0时,代码并不承认没有其他项目可供出售。
:ForestHagShop
cls
set WSwrdHag=1
set WShldHag=1
set GldApHag=1
echo "What would you like, my dear?"
echo 1.) Wooden Sword - 50 gold - (+10 Attack)
echo 2.) Wooden Shield - 70 gold - (+30 Max HP)
echo 3.) Shiny Apple - 40 gold - (+30 HP)
echo.
set /p input6=)
if %input6% equ 1 goto BuySwrdHagChk
if %input6% equ 2 goto BuyShldHag
if %input6% equ 3 goto BuyAplHag
:BuySwrdHagChk
echo Checking...
echo.
echo **PRESS A KEY**
Pause >nul
if WSwrdHag LSS 1 goto OutSwordHag
:BuySwrdHag
set /a Gold=Gold-50
set /a Attack=Attack+10
set /a WSwrdHag=WSwrdHag-1
echo You hand over 50 gold for the
echo wooden sword. Your new stats are...
echo Health Points .. .. .. %HP%/%MaxHP%
echo Gold .. .. .. .. .. .. %Gold%
echo Attack Power .. .. .. %Attack%
echo.
echo **PRESS A KEY**
pause >nul
goto ForestHagShop
:OutSwordHag
echo The hag frowns, looking at you like
echo you're stupid.
echo "You already bought my wood sword,
echo idiot!"
echo.
echo **PRESS A KEY**
pause >nul
goto ForestHagShop
答案 0 :(得分:3)
在检查变量时,您似乎忘记了%
分隔符...
更改
if WSwrdHag LSS 1 goto OutSwordHag
是
if %WSwrdHag% LSS 1 goto OutSwordHag
以及这些
set /a Gold=Gold-50
set /a Attack=Attack+10
set /a WSwrdHag=WSwrdHag-1
是
set /a Gold=%Gold%-50
set /a Attack=%Attack%+10
set /a WSwrdHag=%WSwrdHag%-1