0

I am trying to color specific parts of the text and have managed to succeed partially. I am using the call :colorEcho line to color the text. The line that doesn't work is line 72. It works the first time, in line 54, but not the next. I was just wondering if anyone here knows how to fix this. BTW I got the code from here

@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do     rem"') do (
  set "DEL=%%a"
)
:start
echo You have been studying for years for this moment, to create a human master race, all you have to do is complete the circuit connecting the lightning rods to the speciman.  Do you do it?
ping -n 2 1.1.1.1 > nul
echo.
echo 1) Connect the circuit.
echo 2) No, you take your work and burn it.
echo.
set /p Choice=Choose Now: 
if "%Choice%"=="1" goto awaken
if "%Choice%"=="2" goto end1

:awaken
cls
echo 3
timeout /t 2 /nobreak >nul
cls
echo 2
timeout /t 2 /nobreak >nul
cls
echo 1
timeout /t 2 /nobreak >nul
cls
echo CRACK!!
timeout /t 2 /nobreak >nul
cls
echo Lightning strikes the rod and you see movement coming from the speciman under the sheet on the table.
pause
cls
echo The creature sits up.  It is more disgusting then you ever could have imagined, you are terrified.  It stares at you with mindless eyes, what do you do?
echo.
echo 1) Run for your life.
echo 2) Stay in the Room.
echo.
set /p Choice=Choose Now: 
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm

:run4life [
cls

]

:staycalm [
cls
echo The monster stares at you.
timeout /t 4 /nobreak >nul
echo It screams
timeout /t 1 /nobreak >nul
call :colorEcho 0a "RAAAAUUUGGGHHH"
timeout /t 2 /nobreak >nul
echo.
echo 1) Run for your life.
echo 2) Stay in the Room.
echo.
set /p Choice=Choose Now: 
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm2
]

:staycalm2
[
cls
timeout /t 3 /nobreak >nul
echo You hear a knock at the door.
call :colorEcho 0a " Hello, anyone there?  Someone reported hearing a scream from your residence."
echo.
echo How should you react?
echo.
echo 1) Jump out the window.
echo 2) Answer the door.
echo.
set /p Choice=Choose Now: 
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm3
]

:staycalm3
[
cls
call :colorEcho 0c "Oh yes, I was just scared by a spider."
echo.
timeout /t 2 /nobreak >nul
echo.
call :colorEcho ob "uhhmmm..."
timeout /t 2 /nobreak >nul
echo.
echo.
call :colorEcho 0b "Well, do you mind if I come in just to check around?
]

:end 1
cls
echo Congratulations, you have completed the game without causing anyone to die!
echo.
echo 1) Exit
echo 2) Play Again!
echo.
set /p Choice=Choose Now: 
if "%Choice%"=="1" goto 
if "%Choice%"=="2" goto first

:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
Community
  • 1
  • 1
  • As you can see, people answered your question. If one of the answer indeed answers your question please click the "V" sign next to it. This way it will provide both you and the person who answered with reputation. – Alex Weitz Mar 14 '16 at 10:13

2 Answers2

2

You are using a primitive version of the color print routine that cannot handle characters that are invalid in file names: \, /, :, ", ?, *, &, |, <, >. The version you are using attempts to create a file with a name equal to your displayed string, so it cannot work for your question string.

The top three answers at How to have multiple colors in a Windows batch file? have more sophisticated versions (more complicated), that can handle nearly any character.

Community
  • 1
  • 1
dbenham
  • 119,153
  • 25
  • 226
  • 353
0

The question mark in the text is screwing it up. By the way, I think you mean line 70 is the one that's failing.

Davy C
  • 560
  • 3
  • 16
  • Also, what do you mean by escaped? And how do you do it? – CuseCose Mar 14 '16 at 00:19
  • You are correct that `?` is causing the problem, but everything else about your answer is wrong. The \ / and ? never need to be escaped to be used in a batch file, but ? cannot be used in a file name. And escaping it does no good. – dbenham Mar 14 '16 at 03:17