@echo off
:start1
set /p input=action :
for /f "tokens=1-2 delims= " %%a in ("%input%") do (
goto :%%~a_%%~b >nul 2>&1 || goto start1
)
if I put "| | echo your input is not recognized" it works, but the "goto start1" crashes the script
:explore_room
@echo room explored
goto start1
pause
:examine_door
@echo door examined
pause
:examine_wall
@echo wall examined
pause
@echo off
:start1
set /p input=action :
call :%input: =_% 2>nul
if errorlevel 1 echo your input is not recognized
goto start1
:explore_room
@echo room explored
pause
exit /B 0
:examine_door
echo door examined
pause
exit /B 0
:examine_wall
echo wall examined
pause
exit /B 0
Example:
action : examine door
door examined
Presione una tecla para continuar . . .
action : explore hall
your input is not recognized
action : explore room
room explored
Presione una tecla para continuar . . .
¿Desea terminar el trabajo por lotes (S/N)? s
A way to do that using the technics desribed here : Check if label exists cmd by @MC ND and @dbenham :
@echo off
:start1
set /p input=action :
for /f "tokens=1-2 delims= " %%a in ("%input%") do (
findstr /ri /c:"^ *:%%~a_%%~b " /c:"^ *::%%~a_%%~b$" "%~f0" >nul 2>nul && goto :%%~a_%%~b)
goto:start1
:explore_room
@echo room explored
goto:start1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With