# Solved: batch game (need help)



## vista_narvas (Nov 6, 2012)

hi im working on a small batch game
but iv got a problem


```
echo %N080% %N081% %N082% %N083%
echo %N090% %N091% %N092% %N093%
```
this is a small part of the map
all the variables are set to # or -
(nothing wrong with it)


```
echo wasd to move
set /p move=
if /i {%move%}=={a} goto left
```
simple stuf
(this is not the problem)

```
:left
set /a go=%here%-1
set Ngo=N0%go%
set Nhere=N0%here%
set %Nhere%=-
set %Ngo%=8
set here=%go%
pause
goto :map
```
this makes you move 1 place to the left

here = the place you are now
go = the place you like to go
Nhere = is the N number (%N093%)
Ngo = the N number you like to go

(also working)

but that my problem is when you stand next to a wall (#) you can still walk in it
this is not what i need but i dont know what i can do about it

iv tryed using

```
if {%Ngo%}=={#} goto :cant
```
but that isnt working because
i cant look what is inside the next spot
if i echo %Ngo% i get (N number) of the place but i cant see what is written to that number

i hope i gave enough info about it
(if you like to see all the code ask it ( its a long list of nothing important ) )


----------



## foxidrive (Oct 20, 2012)

Something like this maybe - you have to calculate if the next position is a wall, or check if it is a certain character that represents a wall.


```
:left 
if not left - 1 equals wall (
set /a go=%here%-1
set Ngo=N0%go%
set Nhere=N0%here%
set %Nhere%=-
set %Ngo%=8
set here=%go%
) else (
echo there is a wall there
)
pause
goto :map
```


----------



## vista_narvas (Nov 6, 2012)

foxidrive said:


> Something like this maybe - you have to calculate if the next position is a wall, or check if it is a certain character that represents a wall.
> 
> 
> ```
> ...


thank you for responding
i dont understand what you mean with what you say
i also dont get why i can set something to %Ngo% and it set's it to the N number thing
but when i echo %Ngo% i get the N number and not the value of the number
i cant use something like echo %(%Ngo%)%
to get what the echo the echo from %ngo% say's also between %%


----------



## foxidrive (Oct 20, 2012)

Something like this?


```
d:\>set n80=#

d:\>set ngo=n80

d:\>call echo %%ngo%%
#
```
and a similar example:


```
d:\>set n80=#

d:\>set ngo=n80

d:\>call set wall=%%ngo%%

d:\>echo %wall%
#
```


----------



## vista_narvas (Nov 6, 2012)

foxidrive said:


> Something like this?
> 
> 
> ```
> ...


if i echo %%Ngo%%
i get %Ngo%


----------



## foxidrive (Oct 20, 2012)

I didn't just echo %%ngo%%
Have another look.


----------



## vista_narvas (Nov 6, 2012)

foxidrive said:


> I didn't just echo %%ngo%%
> Have another look.


aaaa stupid me 
with call echo %%Ngo%% i get the same as echo %Ngo%
i aslso get the same with 

```
call set wall=%%ngo%%
echo %wall%
```


----------



## foxidrive (Oct 20, 2012)

Did it solve that issue?

If it didn't then please show us a screen output of your commands


----------



## vista_narvas (Nov 6, 2012)




----------



## vista_narvas (Nov 6, 2012)




----------



## foxidrive (Oct 20, 2012)

Try this:

d:\>set NO80=#

d:\>set go=80

d:\>set ngo=NO%go%

d:\>echo %ngo%
NO80

d:\>call set wall=%%ngo%%

d:\>echo %wall%
#


----------



## vista_narvas (Nov 6, 2012)

i was thinking maybe its possible to export the echo into a text file
and than run the text file inside CMD
but i dont know how and if that would work


----------



## foxidrive (Oct 20, 2012)

It's slower to use files than environment variables.

Why not use:

if "%wall%"=="#" echo You hit a wall&goto :map


----------



## vista_narvas (Nov 6, 2012)

vista_narvas said:


> i was thinking maybe its possible to export the echo into a text file
> and than run the text file inside CMD
> but i dont know how and if that would work












the left window is in cmd (there it works) the middle is the batch file the right window is the script from the file


----------



## vista_narvas (Nov 6, 2012)

foxidrive said:


> It's slower to use files than environment variables.
> 
> Why not use:
> 
> if "%wall%"=="#" echo You hit a wall&goto :map


i know it will be slower but i think it will work
its best if i can keep it inside one file but its not a big problem


----------



## foxidrive (Oct 20, 2012)

When in doubt add some more %




```
@echo off
set N080=#
set here=81
set /a go=%here%-1
set ngo=N0%go%
call set wall=%%%Ngo%%%
echo %wall%
pause
```


----------



## vista_narvas (Nov 6, 2012)

woooow that's it thank you

call set wall=%%%ngo%%%
if {%wall%}=={#} goto :cant


----------

