我已经在批处理文件游戏上工作了一段时间,但我正在制作我正在制作的商店。当我运行脚本并尝试在商店购买东西时,它会给我“缺少操作员”,然后显示购买该项目的消息,但不会将该项目添加到玩家的库存中。继承人的代码。任何帮助深表感谢。
: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
为了清楚起见,剑变量和货币变量在代码
中较早声明答案 0 :(得分:0)
因为你没有定义钱或剑变量行
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
请注意,变量用方括号括起来,所以即使变量未定义,你也至少得到一个有效的行
请注意,set-line中的left-param不能有%-signs,右-param有一个额外的0,所以如果变量未定义,你将得到0 + 1,这是有效的< / p> 不过,你的代码片段中没有缺少资金,我还建议添加
echo off
set money=5000
在脚本的开头