Variables Batch-cmd将字符串声明为数字?

Variables Batch-cmd将字符串声明为数字?,variables,batch-file,if-statement,cmd,set,Variables,Batch File,If Statement,Cmd,Set,我正在制作一个带有库存系统的批量RPG,我想这样做,当用户装备一件武器时,它会将当前的武器串更改为他们装备的武器(在本例中,是一把塔奇剑)。当程序运行并且我装备武器时,它会将当前武器从拳头(默认值)更改为0。发生了什么事 代码如下: :Inventory cls echo Type the number to equip the weapon (Type back to return home) echo Equipped Weapon: %currentweapon% echo. echo W

我正在制作一个带有库存系统的批量RPG,我想这样做,当用户装备一件武器时,它会将当前的武器串更改为他们装备的武器(在本例中,是一把塔奇剑)。当程序运行并且我装备武器时,它会将当前武器从拳头(默认值)更改为0。发生了什么事

代码如下:

:Inventory
cls
echo Type the number to equip the weapon (Type back to return home)
echo Equipped Weapon: %currentweapon%
echo.
echo Weapons:
echo.
if %sword1%==true echo 1- Tachi && set /a anyweps=true
if %anyweps%==false echo You have no weapons.

set /p equip="Enter the number here:"
if %equip%==1 if %sword1%==true set /a currentweapon=Tachi
请帮忙!谢谢

您的错误在这里:

set /a anyweps=true
此处相同:
set/a currentwearm=Tachi

set/a
将设置一个数字,
true
不是一个数字,因此变量将为“0”(数字相当于一个空字符串)

只需卸下
/a

记住:对于字符串,使用
set“var=string”
,对于算术,使用
set/a var=5+2