0

For example:

@echo off
setlocal enabledelayedexpansion
set 101=_
set 102=_
set 103=_
set 104=_
set 105=_
set 106=_
set 107=_
set 108=_
set 109=_
set 110=_
set 111=_
set 112=_
set 113=_
set 114=_
set 115=_
set 116=_
set 201=_
set 202=_
set 203=_
set 204=_
set 205=_
set 206=_
set 207=_
set 208=_
set 209=_
set 210=_
set 211=_
set 212=_
set 213=_
set 214=_
set 215=_
set 216=_
echo !101!!102!!103!!204!!205!!206!!207!!208!!209!!210!!211!!212!!213!!214!!215!!216!
echo !201!!202!!203!!204!!205!!206!!207!!208!!209!!210!!211!!212!!213!!214!!215!!216!

I'm using these numbered variables as coordinates to create a map. The real map will be bigger this is just for example "Currentlocation" is the variable for the current coordinate.

set currentlocation=204
set 204=O

O = the current placement on the map. I want to move left so I would use this:

set /a "currentlocation=currentlocation-1"

While I now have changed the currentlocation variable to the number I want, I also need that new number to become the variable "203". So that way I can change the content of variable 203 to O.

I also want to avoid using a variable search if possible, because I don't want this number to inflict with possible future variables I make.

So basically 203, 204 and currentlocation are variables on there own. The 203 and 204 hold ascii for the map such as =_*O. I need the batch program to recognize I have moved to that location so what I've tried doing is making currentlocation hold the number of the variable I want. So if currentlocation=203 I want the program to notice that the new number matches the variable 203 and replace the 203 variable ascii with O (to signify that i'm currently there on the map) hope this helps clear up any confusion.

Gartoon
  • 1
  • 1
  • 1
    `set "%currentlocation%=O"`? – aschipfl Jun 12 '18 at 01:36
  • I'm going to make the coordinates echo on the screen too so I need the program to tell "203" for example to = O as well – Gartoon Jun 12 '18 at 01:43
  • I can't quite follow that; anyway, to echo the content of the content of `currentlocation` use `call echo %%currentlocation%%` or, if you enable [delayed expansion](http://ss64.com/nt/delayedexpansion.html), echo `!%currentlocation%!`, if that is what you want... – aschipfl Jun 12 '18 at 02:11
  • Ok I get the echoing part. I'll try to explain it a little better – Gartoon Jun 12 '18 at 02:14
  • Yes, that would be great! Please do that by [edit]ing the question! Also examples might be quite useful... – aschipfl Jun 12 '18 at 02:17
  • there updated! :D if you have any other questions I can try to use another example – Gartoon Jun 12 '18 at 02:22
  • 3
    **1.** You should never use Batch variables that start in digit. **2.** I don't understand why you are _combining two subscripts_ into one value. It is much simpler to use separate subscripts for row and col coordinates. **3.** I strongly suggest you to use the _standard array notation_: `set map[1][1]=_` (C++ style) or `set map[1,1]=_` (other languages style); it is much clearer. Then use individual variables for row and col coordinates: `set currentRow=2` and `set currentCol=4` and `set map[%currentRow%,%currentCol%]=O`. – Aacini Jun 12 '18 at 03:22
  • 1
    I suggest you to see [this topic](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) on array management in Batch files. – Aacini Jun 12 '18 at 03:23
  • Thank Aacini! That should help clear up the program a lot. At first I intended making the map 8 by 16 so 8y and 16x, but combine them as 816 so for example 2y 3x = 203 then if you want to move up it's +100 so 303 which doesn't change the x. – Gartoon Jun 12 '18 at 03:34

0 Answers0