问题描述
我正在制作.bat游戏,目前在输入命令时代码为
Im making a .bat game, and currently when putting in a command the code is
set /p command=
我想知道的是您是否可以以某种时间限制输入命令.例如,如果您与一名后卫作战,而您未在5秒钟内未下达命令,则该后卫会发动进攻.
What i want to know is if you can somehow have a time limit for inputting the commands. For example if your fighting a guard, and you haven't put a command in for say 5 seconds, the guard attacks.
这不是迫切需要的东西,我只是想更多地了解即将受到的限制,而且我想我仍然知道这个偏执者(答案是你不能做到)
This is not something of dire need, I am just wondering more about the limitations im bound to, and i think i know the anawer anyway (the answer being that you cant)
谢谢
推荐答案
也可以仅使用批处理来完成.
It can also be done with batch only.
您可以使用start /b
创建第二个线程(在同一窗口中).
如果此线程与set /p
等待用户输入,则主线程不受影响.
该示例将等待5秒钟以供用户输入,如果用户输入了文本,则该文本将被移动到文件中,以便第一个线程可以访问它.
You can create a second thread (in the same window) with start /b
.
If this thread wait with set /p
for user input, the main thread is not affected.
This sample will wait for 5 seconds for userinput, if the user inputs text it is moved into a file, so the first thread can access it.
@echo off
setlocal EnableDelayedExpansion
if "%1" NEQ "" goto %1
del enter.tmp 2>nul >nul
start /b cmd /c %0 :secondThread
:FirstThread
set n=0
echo Enter Text (5 seconds timeout):
:loop
set /a n+=1
ping -n 2 localhost > nul
if !n! LSS 5 (
if not exist entER.tmp goto :loop
< Enter.tmp (
set /p input=
)
echo !input!
) ELSE (
echo Timeout for input
)
exit /b
:secondThread
set /p var=
> enter.tmp echo !var!
exit /b
这篇关于蝙蝠游戏.添加带有/p的计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!