Batch file 批处理文件游戏出现问题,缺少操作员错误

Batch file 批处理文件游戏出现问题,缺少操作员错误,batch-file,cmd,Batch File,Cmd,我一直在一个批处理文件的游戏工作了一段时间,但我有麻烦的商店,我正在做。当我运行脚本并尝试在商店购买物品时,它会给我缺少的操作符,然后显示购买物品的消息,但不会将物品添加到玩家的库存中。这是密码。非常感谢您的帮助 :w_shop title Nova: In the Weapon Shop :sword_screen cls echo. echo You have %money% gold. echo. echo What will you buy? echo 1) Wooden Sword

我一直在一个批处理文件的游戏工作了一段时间,但我有麻烦的商店,我正在做。当我运行脚本并尝试在商店购买物品时,它会给我缺少的操作符,然后显示购买物品的消息,但不会将物品添加到玩家的库存中。这是密码。非常感谢您的帮助

:w_shop

title Nova: In the Weapon Shop

:sword_screen
cls
echo.
echo You have %money% gold.
echo.
echo What will you buy?
echo 1) Wooden Sword: 500 gold
echo You own %sword1%
echo.
echo 2) Stone Sword: 1000 gold
echo You own %sword2%
echo.
echo 3) Iron Blade: 5000 gold
echo You own %sword3%
echo.
echo 4) Mythril Sabre: 7500 gold
echo You own %sword4%
echo.
echo 5) Mythril Longsword: 10000 gold
echo You own %sword5%
echo.
echo 6) Next
echo.
echo 7) Leave Shop
set/p sword_screen=
if %sword_screen% LEQ 0 goto sword_screen
if %sword_screen% GEQ 8 goto sword_screen
if %sword_screen% EQU 1 goto buy_sword1
if %sword_screen% EQU 2 goto buy_sword2
if %sword_screen% EQU 3 goto buy_sword3
if %sword_screen% EQU 4 goto buy_sword4
if %sword_screen% EQU 5 goto buy_sword5
if %sword_screen% EQU 6 goto gauntlet_screen
if %sword_screen% EQU 7 goto main_menu

:buy_sword1

set price=500
set att=100
if %money% LSS %price% goto lack_funds
set/a money=%money%-%price%
set/a %sword1%=%sword1%+1
echo.
echo You bought a Wooden Sword. This weapon has %att% attack.
pause>nul
goto sword_screen

:buy_sword2

set  price=1000
set  att=150
if %money% LSS %price% goto lack_funds
set /a money=%money%-%price%
set /a %sword2%=%sword2%+1
echo.
echo You bought a Stone Sword. This weapon has %att% attack.
pause>nul
goto sword_screen

:buy_sword3

set price=5000
set att=300
if %money% LSS %price% goto lack_funds
set /a money=%money%-%price%
set /a %sword3%=%sword3%+1
echo.
echo You bought a Iron Blade. This weapon has %att% attack.
pause>nul
goto sword_screen

:buy_sword4

set price=7500
set att=500
if %money% LSS %price% goto lack_funds
set /a money=%money%-%price%
set /a %sword4%=%sword4%+1
echo.
echo You bought a Mythril Sabre. This weapon has %att% attack.
pause>nul
goto sword_screen

:buy_sword5

set /a price=10000
set /a att=1000
if %money% LSS %price% goto lack_funds
set /a money=%money%-%price%
set /a %sword5%=%sword5%+1
echo.
echo You bought a Mythril Longsword. This weapon has %att% attack.
pause>nul
goto sword_screen

需要明确的是,代码前面声明了sword变量和money变量,因为您没有在行中定义money或sword变量

if %money% LSS %price% goto lack_funds
set/a %sword1%=%sword1%+1
扩展到

if  LSS 500 goto lack_funds
set/a =+1
这是错误的。这些都是常见的错误。按如下方式更改行:

if [%money%] LSS [%price%] goto lack_funds
set/a sword1=0%sword1%+1
请注意,这些变量被方括号包围,因此即使变量未定义,也至少会得到一行有效的代码

请注意,设置行中的左参数不能有%-符号,右参数还有一个额外的0,因此如果变量未定义,您将得到有效的0+1

顺便说一句,您的代码片段中没有缺少资金标签,而且我建议添加

echo off
set money=5000
在剧本的开头