Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a Variable True and check if the variable is true?

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.

like image 498
YoloJoe Avatar asked Jan 19 '15 15:01

YoloJoe


People also ask

How do you verify a variable?

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.

How do you know if a variable is false?

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!

Is true and == true Python?

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 .


1 Answers

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
like image 126
Vyren Avatar answered Jan 03 '23 20:01

Vyren