0

While I was making my small batch game I thought of implementing a "auto dialog" function. Here it is:

:Background_Work
SET /p Auto_Text=Would you like to have auto dialog on or off (y/n)?
IF '%Auto_Text%'=='y' GOTO Auto_Yes
IF '%Auto_Text%'=='n' GOTO Auto_No
:Auto_Yes
SET TMode=TIMEOUT /t 7 /nobreak
GOTO Speech_Start
:Auto_No
SET TMode=PAUSE
GOTO Speech_Start

Here is what happens after the "auto dialog" function:

:Speech_Start
ECHO Hello, my name is ZERO.
%TMode%

Everything works, if I were to input "y" then it will display the part under ":Speech_Start" as:

Hello, my name is ZERO.

Waiting for 7 seconds, press CTRL+C to quit...

and if I were to input "n" then it will display it as:

Hello, my name is ZERO.

Press any key to continue . . .

The issue I have is, I cant seam to get rid of the TIMEOUT and PAUSE messages. I have tried changing the "auto dialog" function to this:

:Background_Work
SET /p Auto_Text=Would you like to have auto dialog on or off (y/n)?
IF '%Auto_Text%'=='y' GOTO Auto_Yes
IF '%Auto_Text%'=='n' GOTO Auto_No
:Auto_Yes
SET TMode=TIMEOUT /t 7 /nobreak > NUL
GOTO Speech_Start
:Auto_No
SET TMode=PAUSE > NUL
GOTO Speech_Start

But it still displays the default messages. Anyone know how to get rid of them?

5
  • 2
    timeout.... >nul or pause >nul Commented Jun 29, 2017 at 21:08
  • Magoo did you even read the entire post? I said I tried changing it to: SET TMode=TIMEOUT /t 7 /nobreak > NUL and SET TMode=PAUSE > NUL Commented Jun 29, 2017 at 21:10
  • 3
    Nope. Read it just as far as the problem appeared to be. Was expecting the current code as the first item. Oh, well. The problem is that > is a redirector - a special character. If you were to try set tmode before the %tmode% you'd see that tmode doesn't have the >nul. Since > is a special character, you need to escape it with a caret if it's not being used as a redirector. Try SET TMode=PAUSE ^> NUL or preferably SET "TMode=PAUSE ^> NUL" (the quotes ensure unwanted trailing spaces are not included in the value assigned). Commented Jun 29, 2017 at 21:20
  • 1
    Howabout %TMODE% >nul at :Speech_Start ? Commented Jun 29, 2017 at 21:40
  • ohhh... ok. Thanks Magoo. Commented Jun 29, 2017 at 22:33

1 Answer 1

1

As @Magoo says, in your second code snippet, there were two issues that are related to the timeout redirection.


SET TMode=TIMEOUT /t 7 /nobreak > NUL
SET TMode=PAUSE > NUL

In this case > NUL was used to redirect the set prompt to nul, and was not a part of the command. Now the batch file sees TMode as:

TIMEOUT /t 7 /nobreak

or

PAUSE > NUL

Solution A: Suggested by @Magoo

set "TMode=timeout /t 7 /nobreak ^> nul"

This solution escapes the > charactor, making > nul a part of the variable, not the redirection operator.

Solution B: Suggested by @PualH

%TMode% > nul

Very simple; just redirect the command output to nul. Note there is one con:

  • If you want to use multiple of these commands, you need to repeat > nul multiple times.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.