EDIT
I think i formulated myself wrong, the sword is an item you can obtain ingame, so the value starts at 0 (FALSE). When the player obtains the sword, the variable goes to 1 (TRUE). Now, after the variable is true, I want to be able to use
choice /c 12 /n /m "What do you want to do?"
echo.
IF %errorlevel%==1 goto Continiue1
IF %errorlevel%==2 goto Gameover1
**IF %sword%==TRUE choice /c 3 /n /m "[SWORD] -Attack!"**
IF %sword%==TRUE choice /c 3 /n /m "[SWORD] -Attack!"
/EDIT
Please help me understand how I can return a value from a variable and use it later to check if the variable is true. I am new to batch programming, so I'm still learning new things!
@echo OFF
:start
set sword=False
IF %sword%==True echo You have a sword!
echo.
IF %sword%==False echo You don't have a sword.
echo.
pause
I have been searching the web for two days without any luck.
Answer: Use the typeof operator If you want to check whether a variable has been initialized or defined (i.e. test whether a variable has been declared and assigned a value) you can use the typeof operator.
Use the strict equality (===) operator to check if a variable is equal to false - myVar === false . The strict equality operator will return true if the variable is equal to false , otherwise it will return false . Copied!
If you don't know the types of your variables, you may want to refactor your code. But if you really need to be sure it is exactly True and nothing else, use is . Using == will give you 1 == True .
Try this:
@echo off
set sword=true
:start
if %sword% equ true echo You have a sword.
if %sword% neq true echo You do not have a sword.
pause
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With