batch-file

Batch - How To Run Two Commands At The Same Time?


I think someone asked a similar questions ,but mine is a bit different. I have this code:

@echo off
title Game
set time=1 am
timeout 10 /nobreak >nul & goto game
set time=2 am
:game

How can I make the

timeout 5 /nobreak >nul

and

goto game

work at the same time? This is how I want it to work if you still didn't get it: The timeout starts and you play the game after the timeout ends it changes the time to 2 am. How can I do that at the same time and play the game without getting disturbed? Please help. Thanks!


Solution

  • i think you are looking for a "game time", running faster than real time.

    Best way: use another script to set a gametime variable (like below) in a separate (minimized) window. Whenever you need to access the current "gametime" in your main script, use <gametime.dat set /p "gametime="

    GAMETIME.BAT:

    @echo off
    set gametime=10:00
    for /f "tokens=1,2 delims=:" %%a in ("%gametime%") do (
      set hours=%%a
      set mins=%%b
    )
    :loop
    call :increase_gametime
    timeout 5 >nul
    goto :loop
    
    :increase_gametime
     set /a mins+=10
     set /a hours=hours+mins/60
     set /a mins=mins%%60
     set gametime=%hours%:%mins% 
     title %gametime%
    >gametime.dat echo %hours%:%mins%