0

So, me and two other friends are trying to make a text based game running on batch and everything's going smooth, well, except for this one thing, normally on text based games, when a player doesn't write the correct input, the game usually responds something like "don't know what is (the player input)" and in ours, it just bugs and goes on to the next line, so, my question is, how can we be able to fix this and do it the way text based games are supposed to do it?

Thanks!

here is some of the code:

set/p input="What do you want to do?"
if "%input%"=="play" goto :beg: 
if "%input%"=="quit" goto :quit:
if "%input%"=="credits" goto :credits:
if "%input%"=="start" goto :lvl1:
if "%input%"=="ilrdj87imwa" goto :lvl2:
if "%input%"=="valveisevil" goto :lvl3:

pause
  • I'm not sure what you mean by "it just bugs and goes on to the next line", but it sounds like you just need to add some input validation to your code. Take a look here: http://stackoverflow.com/q/684301/328193 – David Jul 27 '12 at 13:10

2 Answers2

2

Without seeing the code you are using it's hard to know what's going wrong.

Try using something like this

:LOOP
set /p input=Enter input
if %input%==ok (
goto :CONTINUE
) else (
echo Wrong input
goto :LOOP
)

:CONTINUE
REM Input ok, carry on

Update

set /p input=What do you want to do?
if "%input%"=="play" goto :beg 
if "%input%"=="play again" goto :pa
if "%input%"=="quit" goto :quit

:play
echo Play
pause >nul

:pa
echo Play again
pause >nul

:quit
exit >nul
Bali C
  • 30,582
  • 35
  • 123
  • 152
  • Yes, but now I've got other problem, if the input is more than a word, it just closes, I've added some of the code to the original post, thanks! – Nuno Renato Guerreiro Jul 27 '12 at 13:27
  • I have updated my answer, with an example of an option with a space, it may have been your syntax causing the problems, it was slightly wrong, try my version and see how you get on. – Bali C Jul 27 '12 at 13:37
0

You could also try using something like this... Im not sure but i think you an use the parameters eq(equals) neg(Negative) Note: the eq might actually be eg but im not sure...

EDIT: The actual parmeters are equ and neg

:loop
set /p choice=

if %choice% equ 1 goto game
if %choice% equ 2 goto info
if %choice% equ 3 goto options
if %choice% equ 4 goto exit
if %choice% neg 1 goto error

:error
echo Error you choose the wrong one...
echo Type c to continue
set /p start=

if %start% egu c goto loop
if %start% egu C goto loop
if %start% neg c goto error
if %start% neg C goto error

You have to put the neg 1 last or the code will never work if you where to not enter 1 if you dont enter in anything then it goes to ERROR