# Two Variables in a set command (MS-DOS)



## Nitekreeper (May 7, 2009)

Making a silly little script, there is way more to it than what is below, but for simplicities sake it's not included.

I'm trying to keep the "receipt" and "purchase success" subscripts work for any purchase you can make, which means alot of variables. All the variables work except the only one that really matters, at the stage where it toggles the itv (item value) to TRUE, it doesn't quite work, I think this is because the set command doesn't like... "two layers" of variables:

*set %itemv%=True*
(Which, if we were to buy a red mushroom would be: *set itv1=true*)

Is there a solution, some character I can enter that will change it completely, or a different command to use altogether?

I'm also open to suggestions of a better way I could do it. 

I hope I haven't made some really noobie mistake.


```
REM -------------------------------------START--------------------------------START

:Start
set name=FAILED
set cash=
set bank=
set itv1=FALSE
set itv2=FALSE
set itv3=FALSE
set itv4=FALSE
set itv5=FALSE
set itv6=FALSE
set itv7=FALSE
set itv8=FALSE
set itv9=FALSE
cls
Echo.
Echo Press 1 to start a new game
Echo Press 2 to load a previous game.
Echo.
set /p start=Well? 
if %start%==1 goto new_game
if %start%==2 goto load_check

REM -------------------------------------START--------------------------------START
REM -------------------------------------ITEMLIST-----------------------------ITEMLIST

:RECRM
set itemname=Red Mushroom
set itemprice=350
set itemv=%itv1%
goto Receipt

:RECBM
set itemname=Blue Mushroom
set Itemprice=350
set itemv=%itv2%
goto Receipt

:RECGM
set itemname=Green Mushroom
set Itemprice=350
set itemv=%itv3%
goto Receipt

REM -------------------------------------ITEMLIST-----------------------------ITEMLIST
REM -------------------------------------RECEIPT------------------------------RECEIPT

:receipt
cls
Echo.
Echo Name:	%name%
Echo Cash:	$%cash%
Echo Bank:	$%bank% 
Echo.
Echo Receipt:
Echo.
Echo Are you sure you wish to purchase:
echo	%itemname%		$%itemprice%
echo.
set /p purchcon=(Y/N): 
if %purchcon%==Y goto PurchaseSuccess
if %purchcon%==N goto shop
goto receipt

REM -------------------------------------RECEIPT------------------------------RECEIPT
REM -------------------------------------PURCHASE SUCCESS---------------------PURCHASE SUCCESS

:PurchaseSuccess
cls
set /a cash=(%cash%-%itemprice%)
set %itemv%=True
          Rem echo %itv1% is to tell me whether or not above line worked.
echo %itv1%
echo.
echo Congratulations you have bought a %itemname%
echo You currently have $%cash%.
echo.
pause
goto shop

REM -------------------------------------PURCHASE SUCCESS---------------------PURCHASE SUCCESS
```


----------



## TheOutcaste (Mar 19, 2009)

You are setting *itemv* equal to the _content_ of each variable, instead of the variable _name_. Use this instead:

```
set itemv=itv1
goto Receipt
...
set %itemv%=True
```
You could also just set *itemv* to the number of the variable:

```
set itemv=1
goto Receipt
...
Set itv%itemv%=True
```
You can't echo the resulting value of the variable though, unless you use delayed expansion:
*Echo !%itemv%!*
Or for the 2nd method
*Echo !itv%itemv%!*


----------



## Nitekreeper (May 7, 2009)

Thanks yet again Outcaste. I don't know why I didn't think of that.


----------

