0

So I am having a problem with changing a text assinged using the set /a here is my script

:wep
cls
if %gold% lss 50 (
echo not enough gold
pause >nul
goto shop
)
if %weap%==Stick (
echo too low on level
pause >nul
goto shop
)
if %wepugrd% lss 1 (
echo You don't have any upgrades
pause
goto shop
)
cls
echo Your Weapon is Being Upgraded
echo.
echo WAIT A FEW SECONDS
ping localhost -n 3 >nul
set /a weapdmg=%weapdmg% + 5
set /a weap=Stick
set /a wepugrd=%wepugrd% - 1
set /a gold=%gold% - 50
echo weapon upgraded
pause
goto shop

the last part is set /a weap=Stick it was earlier fist but instead it just changes fist to 0 instead of changing it to stick can I get some help with that thanx

1 Answers1

0

Use this code:

:wep
cls
if %gold% lss 50 (
    echo not enough gold
    pause >nul
    goto shop
)
if "%weap%"=="Stick" (
    echo too low on level
    pause >nul
    goto shop
)
if %wepugrd% lss 1 (
    echo You don't have any upgrades
    pause
    goto shop
)
cls
echo Your Weapon is Being Upgraded
echo.
echo WAIT A FEW SECONDS
%SystemRoot%\System32\ping.exe localhost -n 3 >nul
set /a weapdmg+=5
set "weap=Stick"
set /a wepugrd-=1
set /a gold-=50
echo weapon upgraded
pause
goto shop

As npocmaka wrote, switch /A is only for arithmetic operations and can't be used if just a string should be assigned to a variable.

Adding or subtracting an integer to an existing value can be also done using the short form as demonstrated above.

And read this answer for reason enclosing weap=Stick in double quotes.

Community
  • 1
  • 1
Mofi
  • 46,139
  • 17
  • 80
  • 143