0

I am trying to make a game with a level selection. If you can't find a solution, can you just make me a new level selection? Anyways, my problem is, I am making the player choose between levels by typing either level 0, "tutorial" level 1, level 2 and level 3. Every time I try to think of a solution I hurt my head. I'm only 11 so that's not a surprise. Here is the code that I need help with:

echo what level do you want?
echo (must have unlocked previous level to play the next)
echo.
echo.
echo tutorial ( lvl0 )
echo lvl1
echo lvl2
echo lvl3
set /p level=enter lvl here:
if level=lvl0 goto let
if level not =lvl1 goto le1
if level not =lvl2 goto le2
if level not =lvl3 goto le3

I also want to make sure that they can't go in level 1 until the tutorial is complete, can't enter level 2 until level 1 is complete and so on. How I am going to get out of this? If you need to ask questions to answer this one, ask it in the comments and I will reply. Anyways, I have another question and don't want to wait 90 minutes to post it.

Is there a way of opening a batch file IN a batch file?

I know, it's simple. But can you open it inside of a second window?

This is for the game I mentioned earlier. If I can't, it will ruin a game-play mechanic I wanted to put in the game. Here is how I opened up in the SAME window.

echo calling hack services...
call C:\Users\%username%\searches\matrix.bat
Mofi
  • 46,139
  • 17
  • 80
  • 143
  • yes.... i TOTTALY know what half of that means! especially because i'm 11! –  Aug 16 '16 at 12:42
  • ok i will do the help thing –  Aug 16 '16 at 12:43
  • also. by a level system, i mean like mario levels. not level up! rpg levels –  Aug 16 '16 at 12:46
  • i'm sorry, I've tried using the "help set" system. but i can not understand what half of it means. if you could find a easier to understand solution that would be awesome. thanks Mofi! –  Aug 16 '16 at 12:55
  • Type `if /?` into a command prompt window, read the help for that command and compare your code with the syntax examples mentioned there... – aschipfl Aug 16 '16 at 13:01
  • 1
    @Imprixie "Subscriber certifies to Stack Exchange that Subscriber is an individual (i.e., not a corporate entity) at least 13 years of age." from https://stackexchange.com/legal. – DavidPostill Aug 16 '16 at 16:47
  • @user6718734 Read the answer on [How to call a batch file, that is two levels up from the current directory](http://stackoverflow.com/a/24725044/3074564) describing the 4 methods to call or start another batch file from within a batch file in same or another process (= console window). – Mofi Aug 18 '16 at 11:49

2 Answers2

1

This is what the beginning of help says:

C:\Windows\system32>if /?
Performs conditional processing in b

IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command

So spaces are important. It is == not =. And Not goes after if. Variables need to be in % signs.

if not %level%==lvl1 goto le1

But this makes no sense, got to level 1 if they don't choose it, then the others don't get checked anyway. So there is no need for not at all.

In Help [NOT] the square brackets means not is optional. Not reverses the test to not equals rather than equals if not is omitted.

if %level%==lvl1 goto le1

The choice command is a better command. See choice /?.

Very basic example - note tests need to be in decending order.

choice /c 12 
If errorlevel 2 goto Level2
If errorlevel 1 goto Level1

You may find an answer at this link useful Trouble with renaming folders and sub folders using Batch.

Community
  • 1
  • 1
Noodles
  • 21
  • 2
  • there is one problem tho. how do i make it so you can only enter level 2 if level 1 is completed? –  Aug 16 '16 at 14:44
1
**echo what level do you want?
echo (must have unlocked previous level to play the next)
echo.
echo.
echo tutorial ( lvl0 )
echo lvl1
echo lvl2
echo lvl3
:qprompt
set /p level=enter lvl here:
if %level%==lv10 goto let
if %level%==lv11 goto let
if %level%==lv12 goto let
if %level%==lv13 goto let
echo The Answer Is Not One of The Choices! Please Try Again
goto qprompt**
robert
  • 31
  • 9
  • It helps more if you supply an explanation why this is the preferred solution and explain how it works. We want to educate, not just provide code. – the Tin Man Jun 29 '20 at 05:21