我的基于文本的游戏脚本不起作用

时间:2015-03-03 23:18:16

标签: batch-file text-based

我正在制作基于文本的RPG,但脚本无效。它与耐力有关。我还有一个任务,取决于你有一定数量的黄金,而且该脚本也不能正常工作。我将包括图片。

:harvest
cls
echo Press 1) to harvest
set /p input17=enter:
if %input17%==1 set   /a wheat= %wheat% + 5
if %input17%==1 set   /a carrots= %carrots% +4
if %input17%==1 set /a stamina= %stamina% - 25 (this line)
if %stamina% < 0 goto nostamina  (this line)
echo.
echo You get some wheat and some carrots.
echo.
echo check your inventory for accurate numbers.
echo. 
echo Press 1) to go back.
pause >nul
goto insidehouse






    :insidehouse
cls

echo You are now inside of your house.
echo.
echo Press 1) to harvest.
echo Press 2) to sell all crops.
echo Press 3) to go into your inventory.
echo Press 4) to sleep eight hours.
echo Press 5) to check for quests.
set /p input16=enter:
if %input16% EQU 1 goto harvest 
if %input16% EQU 2 goto market
if %input16% EQU 3 goto Inventory1
if %input16% EQU 4 goto sleep
if %input16% EQU 5 (and) if %gold% LSS 0 goto shopping (this line)

1 个答案:

答案 0 :(得分:0)

您还没有提供太多代码可以使用,我只能猜测一个解决方案。

我最好的猜测是你试图从for循环内部更新变量。如果是这种情况,您需要将此行添加到批处理文件的顶部:setlocal enabledelayedexpansion。您还需要访问受影响的变量,例如!var!而不是%var%

setlocal enabledelayedexpansion会导致批处理文件中的变量扩展延迟。这在程序的上下文中意味着变量可以在for循环中更新。