Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
@echo off
title ultimate_quiz

:start
cls
echo welcome to
echo the ultimate quiz
echo type s to start
echo type e to exit
set /p set=
if %set% == s goto game
if %set% == e exit

:game 
cls
echo test


i want that wenn i press s it starts the game but it closes it help pls!
making it in notepad++

What I have tried:

i verified if i savec the project i savec and it did not did anything...
Posted
Updated 2-Apr-18 14:42pm
v2

It gets to the end of the batch file, and that means it closes. It's got nothing else to do!
To make it "play a game" you would need to establish a loop of some form: you could use a goto to go back to the "game" label, but you'd need something to let you exit.

To be honest, a batch file isn't the best thing to write a game in, even a simple one! Even a Powershell script[^] would be a better idea, but moving to C# would be a much better solution - you will get much more flexible code (at the code of a steeper learning curve, but much easier code to modify).
 
Share this answer
 
First of all, remove
@echo off

to see error messages.
Quote:
i want that wenn i press s it starts the game

What magic are you using to read the keyboard ?
What magic are you using to get to the game that is not in this code.
if %set% == s goto game

This is not correct batch command, you should learn batch commands really.
 
Share this answer
 
v2
Comments
Dave Kreskowiak 2-Apr-18 20:21pm    
@ECHO OFF only shuts off the display of the commands the batch file is executing. He'll still see any errors those commands throw.

    set /p set=

actually does work for keyboard input. The /P(rompt) sits and waits for keyboard input to set the specified variable, in this case, "set". Not the best choice of variable name though.
Patrice T 2-Apr-18 20:31pm    
"@ECHO OFF only shuts off the display of the commands"
yes, but it also prevent you from seeing which command trow the error message.
I must admit that I haven't made interactive batch for years :)
Of course, it closes. You're double-clicking the batch file to launch it. When the batch file is complete, the CMD window it's using closes automatically.

The solution to that is quite easy. Don't double-click the batch file to launch it. Open a CMD prompt, navigate to the directory where the batch file is located, then launch it from the CMD prompt.

Start -> Run -> CMD
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900