2012-02-04 71 views
-1

帮助。设置menuInput后,这不起作用。它总是只去:opties。 (如果一个类型A,B,C或其他任何东西。谁能说我有什么错?从蝙蝠开始:输入 - > goto不工作

@ECHO off 

:hoofdMenu 
::Dit is het hoofd menu. 
title Hoofdmenu 
echo A. Opties 
echo B. Starten van game 
echo C. Stop programma 
set /P menuInput="Maak een keuze:" 
if %menuInput% == "a" goto opties 
if %menuInput% == "b" goto spelStarten 
if %menuInput% == "c" goto exit 

:opties 
::Geeft alle opties weer -> menu van de opties 
title Opties 
cls 
echo Op dit momment zijn er nog geen opties mogelijk. Sorry. 
pause 
cls 
goto :hoofdMenu 

:spelStarten 
::Starten van het spel 
cls 
title Het spel 
echo Dit is nog in de maak 
pause 
cls 
goto :hoofdMenu 

:exit 
::Sluit het programma 
exit 
+0

请在此发布您的代码,并提供更多详细信息。 – 2012-02-04 18:46:28

回答

2

批处理文件是不是所有的现代编程languagues那么宽容。在这里你去。

if %menuInput%==a goto opties 
if %menuInput%==b goto spelStarten 
if %menuInput%==c goto exit 

不如果你使用的是Windows Vista或更高版本,你应该看看choice命令,这个命令允许你指定允许的字符,而且你不必处理他们按错了键的机会它还有其他一些便利的功能。

+0

谢谢!最好的评论。 =) – 2012-02-04 19:26:42

+0

或者,您可以使用'“%menuInput%”==“a”'等来防止输入为空时的错误。 – schnaader 2012-02-04 19:36:24