【问题标题】:Batch- Issues with Changing Variables/Booleans更改变量/布尔值的批处理问题
【发布时间】:2014-05-26 00:44:45
【问题描述】:

我正在制作 Batch RPG,目前我正在尝试创建一个商店 购买武器和东西。我想这样做,如果玩家有足够的金币 (gld),他们可以购买武器,它会将武器的布尔值更改为 true,并从 gld 变量中带走 20 金币。我究竟做错了什么?它不会减去黄金或将布尔值更改为真。

代码如下:

set /p sword="Enter your selected sword number:"
if %sword%==1 if %gld% GEQ 20 set /a sword1 EQU true 
if %sword%==1 if %gld% GEQ 20 set /a gld EQU %gld%-20
if %sword%==1 if %gld% LSS 20 echo You don't have enough gold!

【问题讨论】:

    标签: variables batch-file cmd


    【解决方案1】:

    问题是您没有正确使用set 命令。

    set /p sword="Enter your selected sword number:"
    if %sword%==1 if %gld% GEQ 20 set sword1=true 
    if %sword%==1 if %gld% GEQ 20 set /a gld-=20
    if %sword%==1 if %gld% LSS 20 echo You don't have enough gold!
    

    你也可以用一个ifelse声明来做同样的事情

    set /p sword="Enter your selected sword number:"
    if %sword%==1 if %gld% GEQ 20 (
        set sword1=true 
        set /a gld-=20
    )  else (
        echo You don't have enough gold!
    ) 
    

    【讨论】:

      猜你喜欢
      • 2011-04-18
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 2022-09-25
      • 1970-01-01
      • 2015-01-29
      • 2013-05-04
      • 1970-01-01
      相关资源
      最近更新 更多