问题
I decided to make a text based adventure and I realized I didn't know much about making one. I do, however, know that I want to make it with a batch file, just because I think it is easier to work with and share. I don't have many questions right now but I'm sure I'll come up with more as time goes on (if I decide this is fun) but right now I have two questions:
How do you make lines appear as if someone was typing it?
How do you make the line wait x seconds before going to the next process (you know for "dramatic effect")
edit I forgot to put the script that I need help with sorry (it's supposed to look like the "wake up neo" screen from The Matrix but I cant get the intervals smaller than 2 or hide the ping text underneath).
echo h
PING 127.0.0.1 -n 2
cls
echo he
PING 127.0.0.1 -n 2
cls
echo hel
PING 127.0.0.1 -n 2
cls
echo hell
PING 127.0.0.1 -n 2
cls
echo hello
PING 127.0.0.1 -n 3
cls
echo hello.
PING 127.0.0.1 -n 3
cls
echo hello..
PING 127.0.0.1 -n 3
cls
echo hello...
PING 127.0.0.1 -n 5
回答1:
Wait/Delay [Source]
PING 127.0.0.1 -n 6 >nul
5 Second Delay
- How it Works: 6 ping echos with default 1 second pause between them with loopback ip.
-n
cannot be less than 2 or there will be no delay.
Delay < 1 Second
PING 10.1.1.1 -n 1 -w 200 >nul
200 Millisecond Delay by using a Private IP Address and the timeout flag -w
. ( only adjust the -w
value and leave -n
as 1 when using this method )
Great Getting Started Resources
Rob van der Woude
SS64
DosTips
ComputerHope
TechNet
Example
Here is an example Typing routine that will print out each character of the message with a 200ms delay between each character.
@echo off
call :Typing "hello..."
exit /b 0
:Typing <Message>
setlocal
set "Message=%~1"
:TypingLoop
ping 10.1.1.1 -n 1 -w 200 >nul
<nul set /p "=%Message:~0,1%"
set "Message=%Message:~1%"
if defined Message goto TypingLoop
endlocal
exit /b 0
来源:https://stackoverflow.com/questions/17839714/text-based-adventure-help-and-tips