1

I am making a dungeon crawling engine in batch. I've made an easy-to-use map editor, but need help with a specific IF statement.

(...)
set Xpos=3
set Ypos=3
set unipos=%Xpos%.%Ypos%
goto map2.2

:map2.2
rem     N
rem   ??=??
rem   ==+==
rem W =?=?= E
rem   ==+==
rem   ??=??
rem     S
set donjon=2.2
set tile1.1=x
set tile1.2=x
set tile1.3=ns
set tile1.4=x
set tile1.5=x
set tile2.1=se
set tile2.2=ew
set tile2.3=nsew
set tile2.4=ew
set tile2.5=sw
set tile3.1=nsw
set tile3.2=x
set tile3.3=nsew
set tile3.4=x
set tile3.5=nse
set tile4.1=ne
set tile4.2=ew
set tile4.3=nsew
set tile4.4=ew
set tile4.5=nw
set tile5.1=x
set tile5.2=x
set tile5.3=ns
set tile5.4=x
set tile5.5=x
goto inroom

:inroom
set tile=tile
set roomcheck=%tile%%unipos%
set retire=inroom
cls
echo  [%name1%] HP: %hp1%/%xhp1%
if 1==%friend2% echo  [%name2%] HP: %hp2%/%xhp2%
if 1==%friend3% echo  [%name3%] HP: %hp3%/%xhp3%
echo ==================================================
echo.
echo  You are now at room %unipos%. %roomcheck%
if nsew==%roomcheck% echo  There are exits in all four directions.
echo.

What comes out when the map is loaded is this:

[Your name] HP: 300/300

You are now at room3.3. tile3.3

I need to know how one searches for a variable when another variable exists within the title! I probably phrased that horribly wrong, but "%tile%%unipos%" was the best I could come up with. Its a... placeholder, if you will.

1 Answers1

1

you need delayed expansion:

@echo off
setlocal enabledelayedexpansion

set "tile3.3=nsew"
set "unipos=3.3"
set "roomcheck=!tile%unipos%!"
echo %roomcheck%
Community
  • 1
  • 1
Stephan
  • 53,940
  • 10
  • 58
  • 91