Zimano
Zimano

Reputation: 2299

Cannot change variable in batch script conditionally

This batch script always gives the answer "You make some 0" instead of other options. What did I do wrong here?

set /a foodcalc=0
set /a dish=0
set /a food1=1   
set /a food2=2    
set /a food3=3    
set /a food4=4    
SET /a foodcalc=4*%random%/32768+1    
IF foodcalc==1 set /a dish food1    
IF foodcalc==2 set /a dish food2    
IF foodcalc==3 set /a dish food3    
IF foodcalc==4 set /a dish food4
echo You make some %dish%.    
ping localhost -n 3 >nul    
goto actualgame

Upvotes: 0

Views: 849

Answers (2)

VirtualTroll
VirtualTroll

Reputation: 3091

IF %foodcalc%==1 set /a dish=food1
IF %foodcalc%==2 set /a dish=food2
IF %foodcalc%==3 set /a dish=food3
IF %foodcalc%==4 set /a dish=food4 

Upvotes: 1

PA.
PA.

Reputation: 29339

need to use % to refer back to the contents of a variable, this way

     if %foodcalc%==1 echo one!

Upvotes: 2

Related Questions