X Y grid help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

X Y grid help

#1 Post by batnoob » 01 May 2017 10:43

I am trying to make an XY grid so I can make a character go up and down (in my previous post you can see I only had side to side movement). When I run this, it either says:
Do is unexpected at this time,
OR
'Board.bat' is not recognized as an internal or external command, operable program or batch file.

:::::: Board.bat :::::::::

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set X=0
set Y=0
:b
set "_CLS=%1"
set "_LNS=%2"
set "wall=%3"
set "chr=%4
set "charsp=%5"

set /a "_CLS=%_CLS%"
set /a "_COLS=%_CLS%+1"
set /a "_LNS=%_LNS%"
set /a "_LINS=%_LNS%+1"

:start
cls

:begin
for /l %%h in (1 1 %_LINS%) do (
   for /l %%w in (1 1 %_COLS%) do (
      set "%%w@%%h=+"
   )
)
set top=
for /l %%h in (1 1 %_LINS%) do (
   if %%h == 1 (for /l %%w in (1 1 %_COLS%) do (set top=%wall%!top!))
   if %%h == 1 (echo %wall%!top!%wall%)

   set row=
   for /l %%w in (1 1 %_LINS%) do (
      set row=!row!!%%w@%%h!
   )
   echo %wall%!row!%wall%
   IF %%h EQU %height% (FOR /L %%w IN (1, 1, %_COLS%) DO (SET TOP=~!TOP!))
   IF %%h EQU %height% ECHO %wall%!top!%wall%
)
   
endlocal


::::::: batch_file_that_calls_Board.bat ::::::::

Code: Select all

@echo off
color 70
:1
cls
set cs=88
set ls=44
set ch=+
set wl=Û
REM set /p "cc=Character Space (X@Y): "

set "_CS=%cs%
set "_LS=%ls%

set /a cls=cs+5
set /a lns=ls+5
mode con cols=%cls% lines=%lns%

:game
REM set cp=%_CS%@%_LS%
cls
CALL Board.bat %cs% %ls% %wl% %ch%
pause
goto :game
exit

Thanks, BatNoob

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: X Y grid help

#2 Post by aGerman » 01 May 2017 11:50

DO belongs to the syntax of FOR loops. It doesn't belong to IF statements.

Steffen

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: X Y grid help

#3 Post by Aacini » 01 May 2017 12:41

This is your code with a couple small errors fixed, and some code rearrangements to made it better:

Code: Select all

@echo off
color 70

cls
set cs=88
set ls=44
set ch=+
set wl=Û
REM set /p "cc=Character Space (X@Y): "

set /a "_CS=cs, cls=cs+5, _LS=ls, lns=ls+5"
mode con cols=%cls% lines=%lns%

:game
REM set cp=%_CS%@%_LS%
CALL Board.bat %cs% %ls% %wl% %ch%
pause
goto :game
exit

Board.bat:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set /a "_CLS=%1, _COLS=_CLS+1, _LNS=%2, _LINS=_LNS+1"
set "wall=%3"
set "chr=%4"
REM set "charsp=%5"

:start
cls

:begin
REM Initialize "top" variable just once, before the main FOR loop
set "top="
for /l %%w in (1 1 %_COLS%) do (
   set "top=%wall%!top!"
)

for /l %%h in (1 1 %_LINS%) do (
   for /l %%w in (1 1 %_COLS%) do (
      set "%%w@%%h=%chr%"
   )
)

for /l %%h in (1 1 %_LINS%) do (

   if %%h == 1 echo %wall%%top%%wall%

   set "row="
   for /l %%w in (1 1 %_COLS%) do (
      set "row=!row!!%%w@%%h!"
   )
   echo %wall%!row!%wall%

   IF %%h EQU %_LINS% ECHO %wall%%top%%wall%
)

exit /B

Antonio

batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Re: X Y grid help

#4 Post by batnoob » 01 May 2017 14:00

Thank you, now all I have to do is figure out why yours works and not mine!

Post Reply