I am doing an RPG game in batch file and I want to make a challenge for user to type word like ‚butter’ in 5 seconds. If he’s not going to do this he will get nothing and go back. But if he is going to type correctly he will gain money. And I want it to show timer. Can you guys help? Could it be done with the PING command?
Asked
Active
Viewed 62 times
-4
-
4This site is for help with specific coding issues, where you post your failing code with sufficient background and explanation of the issue for readers to replicate it and potentially help. Without the forementioned code and information, your question is unclear, too broad and off-topic here. Please [edit your question](https://stackoverflow.com/posts/50630539/edit) to rectify matters, before your question is closed as such. – Compo May 31 '18 at 18:27
-
Compo that’s the point. I don’t know command for it. – Ionicjohn May 31 '18 at 18:29
-
2Unfortunately we are not a free AI service/personal search facility; do some research and/or ask on an appropriate forum. Take the [tour], read up on [ask], then create a [mcve], otherwise things will be unlikely to move on from where they are now. – Compo May 31 '18 at 18:36
-
I tried to search in the internet but all of them was questions without answers. And I know that’s not an forum for AI. – Ionicjohn May 31 '18 at 18:38
-
I searched this site for "timed input" terms and found [this answer](https://stackoverflow.com/a/33686109/778560), and [this one](https://stackoverflow.com/a/28196468/778560), and [this one](https://stackoverflow.com/a/46554879/778560), and... – Aacini May 31 '18 at 20:28
1 Answers
1
Counting your effort, you don't deserve it.
Just to give you a starting point,
batch isn't good in measuring/handling/calculating time.
:: Q:\Test\2018\05\31\typingtest.cmd
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
:loop
cls
Echo enter butter
choice /n /C b >NUL
set start=%time%
choice /n /C u >NUL
choice /n /C t >NUL
choice /n /C t >NUL
choice /n /C e >NUL
choice /n /C r >NUL
set ready=%time%
Echo start:%start%
Echo ready:%ready%
Sample output:
enter butter
start:21:00:50,50
ready:21:00:51,56
Despite my initial comment, the following version is more universal and calculates seconds correctly provided your %time%
retuns 24hr format and hundreds seconds.
:: Q:\Test\2018\05\31\typingtest.cmd
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
cls
Echo enter butter
Set "Start="
For %%A in (b u t t e r) do (
choice /n /C %%A >NUL
if not defined Start Set "Start=%time%"
)
Set "Ready=%time%"
Call :CalcTime Start
Call :CalcTime Ready
Set /A "Lapse=Ready-Start"
Echo Secs : %Lapse:~0,-2%,%Lapse:~-2%
Pause
Goto :Eof
:CalcTime
Echo=%1: !%1!
For /f "tokens=1-4delims=:.," %%H in ("!%1!"
) Do Set /A "%1=(1%%H-100)*360000+(1%%I-100)*6000+(1%%J-100)*100+%%K"
Sample output:
enter butter
Start: 16:25:43,42
Ready: 16:25:46,94
Secs : 3,52
-
I tried to make it in C#, but I don’t know this language very well. So I started it in batch. And thanks for source code :). – Ionicjohn May 31 '18 at 20:49
-
Consider learning one of the popular general purpose programming languages, that are considered relatively easy to learn, such as Python, JavaScript, Ruby, etc etc. Use the right tool for a given problem. Please don't ask how to tighten a Philips head screw with a ballpeen hammer. – WarrenT May 31 '18 at 22:38