I'm trying to make an option for my batch game to change the color using a variable, but It doesn't change, here's all the coding associated with the coloring, (heads up, it's pretty long,) did I do something wrong?
:colorchoice1
cls
color 8
set /a %cChoice% = 0
echo so, what color do you want?
echo.
echo 1) black (that'd make it pretty hard to see, huh?)
echo 2) blue
echo 3) green
echo 4) aqua
echo 5) red
echo 6) purple
echo 7) yellow
echo 8) white
echo 9) more options
set /p cChoice=
if %cChoice% == 1 color 0
goto confirmcolor
if %cChoice% == 2 color 1
goto confirmcolor
if %cChoice% == 3 color 2
goto confirmcolor
if %cChoice% == 4 color 3
goto confirmcolor
if %cChoice% == 5 color 4
goto confirmcolor
if %cChoice% == 6 color 5
goto confirmcolor
if %cChoice% == 7 color 6
goto confirmcolor
if %cChoice% == 8 color 7
goto confirmcolor
if %cChoice% == 9 goto colorchoice2
goto colorchoice1
:colorchoice2
cls
color 8
set /a %cChoice% = 0
echo so, what color do you want?
echo.
echo 10) grey (default)
echo 11) light blue
echo 12) light green
echo 13) light aqua
echo 14) light red (pink)
echo 15) light purple
echo 16) light yellow
echo 17) bright white
echo 18) back to other options
I feel like the problem is somewhere past this point
set /p cChoice=
if %cChoice% == 10 color 8
goto confirmcolor
if %cChoice% == 11 color 9
goto confirmcolor
if %cChoice% == 12 color A
goto confirmcolor
if %cChoice% == 13 color B
goto confirmcolor
if %cChoice% == 14 color C
goto confirmcolor
if %cChoice% == 15 color D
goto confirmcolor
if %cChoice% == 16 color E
goto confirmcolor
if %cChoice% == 17 color F
goto confirmcolor
if %cChoice% == 18 goto colorchoice1
goto colorchoice 2
:confirmcolor
cls
echo are you sure this is the color you want?
echo (remember, this cannot be changed later)
echo.
echo.
echo 1) yes
echo 2) no
set /p confcolor=
if %confcolor% == 1 goto name
if %confcolor% == 2 goto colorchoice1
goto confirmcolor
You are not using multiline if statements. Right now, you are only telling the if to run the command that is on the same line as the check. Because of this, the goto confirmcolor command that is under if %cChoice% == 1 color 0 gets called regardless of what choice was picked.
There are two ways to fix this: You can either use parentheses to make multi-line if statements like this:
if %cChoice% == 1 (
color 0
goto confirmcolor
)
if %cChoice% == 2 (
color 1
goto confirmcolor
)
Or, because that's horribly redundant, you can just have one last check at the end of all the checks, like this:
set /p cChoice=
echo *%cChoice%* selected.
if %cChoice% == 1 color 0
if %cChoice% == 2 color 1
if %cChoice% == 3 color 2
if %cChoice% == 4 color 3
if %cChoice% == 5 color 4
if %cChoice% == 6 color 5
if %cChoice% == 7 color 6
if %cChoice% == 8 color 7
if %cChoice% == 9 goto colorchoice2
if %cChoice% lss 9 goto confirmcolor
goto colorchoice1
Related
i am trying to make character ("o") be able to enter both of the buldings, i've tried everything:
detecting %pos% so when its 5 it goes to :fishing store
adding "e" to choices so if i press e and %pos% equals 5 them goto :fishing store
(none of them worked, beacause i am doing something wrong and i don't know what)
ill be greatfull if someone will respond quickly
here is the code:
#echo off
title outside
mode 45,10
set/a pos=11
set "y7=[fishing] [ fanta's ]"
set "y6=[ store ] [ house ]"
set "y5=H-------H H---------H"
set "y4=H_II____H H_II______H"
set "y3=H___[ ]_H__o__H___[ ]___H__________"
set "y2=::::::::::::::::::::::::H\/\/H\/\/H"
set "y1=::::::::::::::::::::::::H/\/\H/\/\H~~~~~~~~~~"
echo %y7%
echo %y6%
echo %y5%
echo %y4%
echo %y3%
echo %y2%
echo %y1%
goto movement
:movement
choice /c ad /n
if %errorlevel% equ 1 goto left
if %errorlevel% equ 2 goto right
:left
if %pos% gtr 1 set /a pos-=1
goto position
:right
if %pos% lss 32 set /a pos+=1
goto position
:position
if %pos% EQU 1 set "y3=o___[ ]_H_____H___[ ]___H__________"
if %pos% EQU 2 set "y3=Ho__[ ]_H_____H___[ ]___H__________"
if %pos% EQU 3 set "y3=H_o_[ ]_H_____H___[ ]___H__________"
if %pos% EQU 4 set "y3=H__o[ ]_H_____H___[ ]___H__________"
if %pos% EQU 5 set "y3=H___[o]_H_____H___[ ]___H__________"
if %pos% EQU 6 set "y3=H___[ ]oH_____H___[ ]___H__________"
if %pos% EQU 7 set "y3=H___[ ]_o_____H___[ ]___H__________"
if %pos% EQU 8 set "y3=H___[ ]_Ho____H___[ ]___H__________"
if %pos% EQU 9 set "y3=H___[ ]_H_o___H___[ ]___H__________"
if %pos% EQU 10 set "y3=H___[ ]_H__o__H___[ ]___H__________"
if %pos% EQU 11 set "y3=H___[ ]_H___o_H___[ ]___H__________"
if %pos% EQU 12 set "y3=H___[ ]_H____oH___[ ]___H__________"
if %pos% EQU 13 set "y3=H___[ ]_H_____o___[ ]___H__________"
if %pos% EQU 14 set "y3=H___[ ]_H_____Ho__[ ]___H__________"
if %pos% EQU 15 set "y3=H___[ ]_H_____H_o_[ ]___H__________"
if %pos% EQU 16 set "y3=H___[ ]_H_____H__o[ ]___H__________"
if %pos% EQU 17 set "y3=H___[ ]_H_____H___[o]___H__________"
if %pos% EQU 18 set "y3=H___[ ]_H_____H___[ ]o__H__________"
if %pos% EQU 19 set "y3=H___[ ]_H_____H___[ ]_o_H__________"
if %pos% EQU 20 set "y3=H___[ ]_H_____H___[ ]__oH__________"
if %pos% EQU 21 set "y3=H___[ ]_H_____H___[ ]___o__________"
if %pos% EQU 22 set "y3=H___[ ]_H_____H___[ ]___Ho_________"
if %pos% EQU 23 set "y3=H___[ ]_H_____H___[ ]___H_o________"
if %pos% EQU 24 set "y3=H___[ ]_H_____H___[ ]___H__o_______"
if %pos% EQU 25 set "y3=H___[ ]_H_____H___[ ]___H___o______"
if %pos% EQU 26 set "y3=H___[ ]_H_____H___[ ]___H____o_____"
if %pos% EQU 27 set "y3=H___[ ]_H_____H___[ ]___H_____o____"
if %pos% EQU 28 set "y3=H___[ ]_H_____H___[ ]___H______o___"
if %pos% EQU 29 set "y3=H___[ ]_H_____H___[ ]___H_______o__"
if %pos% EQU 30 set "y3=H___[ ]_H_____H___[ ]___H________o_"
if %pos% EQU 31 set "y3=H___[ ]_H_____H___[ ]___H_________o"
:fanta's house
cls
echo you are at fanta's house
pause
:fishing store
cls
echo you are at fishing store
pause
:print
cls
echo %y7%
echo %y6%
echo %y5%
echo %y4%
echo %y3%
echo %y2%
echo %y1%
if %pos% EQU 5 choice /c ead /n >nul
if %errorlevel% equ 1 goto :fishing store
if %pos% EQU 17 choice /c ead /n >nul
if %errorlevel% equ 1 goto :fanta's house
if %errorlevel% equ 2 goto :left
if %errorlevel% equ 3 goto :right
goto movement
Firstly, make sure your file extension is .cmd and not .bat
Then something like this should help guide you.
Just replace your print section with this:
:print
cls
echo %y7%
echo %y6%
echo %y5%
echo %y4%
echo %y3%
echo %y2%
echo %y1%
if %pos% EQU 5 choice /c ead /n >nul
if %errorlevel% equ 1 goto :fishingstore
if %errorlevel% equ 2 goto :left
if %errorlevel% equ 3 goto :right
if %pos% EQU 17 choice /c ead /n >nul
if %errorlevel% equ 1 goto :fantashouse
if %errorlevel% equ 2 goto :left
if %errorlevel% equ 3 goto :right
goto movement
As you seemed to have changed your original code, try this exact full version:
#echo off
title outside
mode 45,10
set/a pos=11
set "y7=[fishing] [ fanta's ]"
set "y6=[ store ] [ house ]"
set "y5=H-------H H---------H"
set "y4=H_II____H H_II______H"
set "y3=H___[ ]_H__o__H___[ ]___H__________"
set "y2=::::::::::::::::::::::::H\/\/H\/\/H"
set "y1=::::::::::::::::::::::::H/\/\H/\/\H~~~~~~~~~~"
echo %y7%
echo %y6%
echo %y5%
echo %y4%
echo %y3%
echo %y2%
echo %y1%
goto movement
:movement
choice /c ad /n
if %errorlevel% equ 1 goto left
if %errorlevel% equ 2 goto right
:left
if %pos% gtr 1 set /a pos-=1
goto position
:right
if %pos% lss 32 set /a pos+=1
goto position
:position
if %pos% EQU 1 set "y3=o___[ ]_H_____H___[ ]___H__________"
if %pos% EQU 2 set "y3=Ho__[ ]_H_____H___[ ]___H__________"
if %pos% EQU 3 set "y3=H_o_[ ]_H_____H___[ ]___H__________"
if %pos% EQU 4 set "y3=H__o[ ]_H_____H___[ ]___H__________"
if %pos% EQU 5 set "y3=H___[o]_H_____H___[ ]___H__________"
if %pos% EQU 6 set "y3=H___[ ]oH_____H___[ ]___H__________"
if %pos% EQU 7 set "y3=H___[ ]_o_____H___[ ]___H__________"
if %pos% EQU 8 set "y3=H___[ ]_Ho____H___[ ]___H__________"
if %pos% EQU 9 set "y3=H___[ ]_H_o___H___[ ]___H__________"
if %pos% EQU 10 set "y3=H___[ ]_H__o__H___[ ]___H__________"
if %pos% EQU 11 set "y3=H___[ ]_H___o_H___[ ]___H__________"
if %pos% EQU 12 set "y3=H___[ ]_H____oH___[ ]___H__________"
if %pos% EQU 13 set "y3=H___[ ]_H_____o___[ ]___H__________"
if %pos% EQU 14 set "y3=H___[ ]_H_____Ho__[ ]___H__________"
if %pos% EQU 15 set "y3=H___[ ]_H_____H_o_[ ]___H__________"
if %pos% EQU 16 set "y3=H___[ ]_H_____H__o[ ]___H__________"
if %pos% EQU 17 set "y3=H___[ ]_H_____H___[o]___H__________"
if %pos% EQU 18 set "y3=H___[ ]_H_____H___[ ]o__H__________"
if %pos% EQU 19 set "y3=H___[ ]_H_____H___[ ]_o_H__________"
if %pos% EQU 20 set "y3=H___[ ]_H_____H___[ ]__oH__________"
if %pos% EQU 21 set "y3=H___[ ]_H_____H___[ ]___o__________"
if %pos% EQU 22 set "y3=H___[ ]_H_____H___[ ]___Ho_________"
if %pos% EQU 23 set "y3=H___[ ]_H_____H___[ ]___H_o________"
if %pos% EQU 24 set "y3=H___[ ]_H_____H___[ ]___H__o_______"
if %pos% EQU 25 set "y3=H___[ ]_H_____H___[ ]___H___o______"
if %pos% EQU 26 set "y3=H___[ ]_H_____H___[ ]___H____o_____"
if %pos% EQU 27 set "y3=H___[ ]_H_____H___[ ]___H_____o____"
if %pos% EQU 28 set "y3=H___[ ]_H_____H___[ ]___H______o___"
if %pos% EQU 29 set "y3=H___[ ]_H_____H___[ ]___H_______o__"
if %pos% EQU 30 set "y3=H___[ ]_H_____H___[ ]___H________o_"
if %pos% EQU 31 set "y3=H___[ ]_H_____H___[ ]___H_________o"
:print
cls
echo %y7%
echo %y6%
echo %y5%
echo %y4%
echo %y3%
echo %y2%
echo %y1%
if %pos% EQU 5 choice /c ead /n >nul
if %errorlevel% equ 1 goto :fishingstore
if %pos% EQU 17 choice /c ead /n >nul
if %errorlevel% equ 1 goto :fantashouse
if %errorlevel% equ 2 goto :left
if %errorlevel% equ 3 goto :right
goto movement
goto :EOF
:fantashouse
cls
echo you are at fanta's house
choice /c ce /m "Continue or exit?"
if %errorlevel% equ 2 goto :print
pause
goto :EOF
:fishingstore
cls
echo you are at fishing store
choice /c ce /m "Continue or exit?"
if %errorlevel% equ 2 goto :print
pause
goto :EOF
#ECHO OFF
SETLOCAL
title outside
rem mode 45,10
set/a pos=11
:position
set "y3=H___[ ]_H_____H___[ ]___H__________"
SET /a y7=pos+1
CALL SET "y3=%%y3:~0,%pos%%%o%%y3:~%y7%%%"
set "y7=[fishing] [ fanta's ]"
set "y6=[ store ] [ house ]"
set "y5=H-------H H---------H"
set "y4=H_II____H H_II______H"
set "y2=::::::::::::::::::::::::H\/\/H\/\/H"
set "y1=::::::::::::::::::::::::H/\/\H/\/\H~~~~~~~~~~"
cls
echo %y7%
echo %y6%
echo %y5%
echo %y4%
echo %y3%
echo %y2%
echo %y1%
:: goto movement
:movement
SET "choices=ad"
IF %pos% equ 5 SET "choices=ade"
IF %pos% equ 19 SET "choices=ade"
choice /c %choices% /n
if %errorlevel% equ 1 goto left
if %errorlevel% equ 2 goto right
IF %pos% equ 19 GOTO fanta's
IF %pos% equ 5 GOTO fishing
:left
if %pos% geq 1 set /a pos-=1
goto position
:right
if %pos% lss 32 set /a pos+=1
goto position
:fanta's house
cls
echo you are at fanta's house
pause
goto position
:fishing store
cls
echo you are at fishing store
pause
goto position
GOTO :EOF
A somewhat re-written version.
Since all that changes on the map is the position of o, place the o on the appropriate position on the line y3.
the first character in a string is "character 0" (hence, it's legitimate for pos to reach 0 - and gtr becomes geq in left:). Batch can substring using the syntax var:~start,length where start is the starting character number (or character-count from end, if negative) and length is number of characters (if negative, number of characters to not include).
So, we need to select that part of y3 from the start to pos, then the o and then the remainder of y3 starting at pos+1.
Hence - calculate pos+1 as batch can't apply a calculation in the substring formula and put the result in a temporary variable. I chose y7 since it's about to be reset anyway. and then use the parser to complete the extraction.
The parser examines CALL SET "y3=%%y3:~0,%pos%%%o%%y3:~%y7%%%" and replaces, left-to-right (let's assume pos=11, hence y7=12) %% with % and %var% with var's value since the set is being called:
set "y3=% y3:~0, 11 % o % y3:~ 12 %" (spaces inserted to show parser's steps)
set "y3=%y3:~0,11%o%y3:~12%" (as executed)
which places the o appropriately, depending on pos.
Our next step is whether o is at position 5 or 19 (not 17), when we need to allow e as well as a and d in the choice. Simply append the e in these circumstances, and choice will yield errorlevel 1 for a, 2 for d and 3 for e (but only if e is one of the choices).
Then - well, if choice has returned errorlevel 1 or 2, go left/right and if it's neither of those, then it must be 3, so e was pressed and we can look at pos to see which of the two routines to jump to.
Note that a label can't contain spaces, so if you tried fanta's house fanta's shop and fanta's tennis court then only the label fanta's would be interpreted (it's unusual, but not invalid, to use ' in a label). cmd would search for the next label fanta's following the goto as its destination, which might give the illusion of working correctly - but that's a trap...
#echo off
mode 1000
goto block1
:block1
echo color
goto block2
:block2
pause
set /a num=%random% %%5
goto 0
:0
if num == 0 goto a
goto 1
:1
if num == 1 goto b
goto 2
:2
if num == 2 goto c
goto 3
:3
if num == 3 goto d
goto 4
:4
if num == 4 goto e
goto 5
:5
if num == 5 goto f
goto 0
:a
color 0a
goto block2
:b
color 0b
goto block2
:c
color 0c
goto block2
:d
color 0d
goto block2
:e
color 0e
goto block2
:f
color 0f
goto block2
i want to make a color sign witch changes colors and i would like use simething like this . but i cant use else in batch and it would need something like that
From batch view point nearly all the gotos are useless and only
result in spaghetti code.
You are aware that a color stement will affect the whole screen?
%random% modulus 5 can only return 0..4
Your code shortened :
#echo off
mode 1000
echo color
:block2
pause
set /a num=%random% %%5
if %num% == 0 color 0a
if %num% == 1 color 0b
if %num% == 2 color 0c
if %num% == 3 color 0d
if %num% == 4 color 0e
goto block2
I made a parrot logo for an project and I want it to build before loading a basic trivia game I also made.
Whenever the image builds it closes when it finishes, I am unsure of how to make this work.
#echo off
cls
echo LOADING GAME...
ping localhost -n 5 >nul
#echo off
:loop
:menu
cls
color 0b
echo Trivia Game
ping localhost -n 5 >nul
color 0e
:loop
:menu
echo Made by River Davis
echo=================================================================================
echo 1)Start
echo 2)Options/Info
echo 3)exit
echo=================================================================================
set /p hi=
if not defined hi (
cls
goto loop
)
if %hi% == 1 goto Game
if %hi% == 2 goto Options/Info
if %hi% == 3 exit
:menu1
cls
color 0b
echo Trvia Game
ping localhost -n 5 >nul
color 0a
:loop
:menu
echo Made by River Davis
echo=================================================================================
echo 1)Start
echo 2)Options/Info
echo 3)exit
echo=================================================================================
set /p hi=
if not defined hi (
cls
goto loop
)
if %hi% == 1 goto Game
if %hi% == 2 goto Options/Info
if %hi% == 3 exit
:menu2
cls
color 0b
echo Trivia Game
ping localhost -n 5 >nul
color 0b
:loop
:menu
echo Made by River Davis
echo=================================================================================
echo 1)Start
echo 2)Options/Info
echo 3)exit
echo=================================================================================
set /p hi=
if not defined hi (
cls
goto loop
)
if %hi% == 1 goto Game
if %hi% == 2 goto Options/Info
if %hi% == 3 exit
:menu3
cls
color 0b
echo Trivia Game
ping localhost -n 5 >nul
color 0c
:loop
:menu
echo Made by River Davis
echo=================================================================================
echo 1)Start
echo 2)Options/Info
echo 3)exit
echo=================================================================================
set /p hi=
if not defined hi (
cls
goto loop
)
if %hi% == 1 goto Game
if %hi% == 2 goto Options/Info
if %hi% == 3 exit
:menu4
cls
color 0b
echo Trivia Game
ping localhost -n 5 >nul
color 0d
:loop
:menu
echo Made by River Davis
echo=================================================================================
echo 1)Start
echo 2)Options/Info
echo 3)exit
echo=================================================================================
set /p hi=
if not defined hi (
cls
goto loop
)
if %hi% == 1 goto Game
if %hi% == 2 goto Options/Info
if %hi% == 3 exit
:menu5
cls
color 0b
echo Trivia Game
ping localhost -n 5 >nul
color 0f
:loop
:menu
echo Made by River Davis
echo=================================================================================
echo 1)Start
echo 2)Options/Info
echo 3)exit
echo=================================================================================
set /p hi=
if not defined hi (
cls
goto loop
)
if %hi% == 1 goto Game
if %hi% == 2 goto Options/Info
if %hi% == 3 exit
:game
cls
echo What's Your Name?
set /p name=
echo Hello %name%! Would you like to start (y/n)
set /p start=
if %start% == y goto lvl1
if %start% == Y goto lvl1
if %start% == n goto menu
if %start% == N goto menu
goto start game
:Options/Info
cls
echo============================
echo This game was made for
echo Mrs.Crosby's class by
echo River Davis in 2016
echo============================
echo choose a Menu Colour
echo colours=0a,Light Green/ 0b,Light Aqua/ 0c,Light Red/ 0d,Light purple/
echo 0e,Light Yellow/ 0f,White
set /p color=
%color%
if %color%== 0a goto menu1
if %color%== 0b goto menu2
if %color%== 0c goto menu3
if %color%== 0d goto menu4
if %color%== 0e goto menu
if %color%== 0f goto menu5
:lvl1
cls
echo Question 1)
echo what does 1+2+3+4+5+6+7+8+9 equal
echo a.45
echo b.50
echo c.62
echo d.55
set /p ha=
if %ha% == a goto crl
if %ha% == b goto wrl
if %ha% == c goto wrl
if %ha% == d goto wrl
goto lvl1
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p ha=
if %ha% == y goto lvl2
if %ha% == Y goto lvl2
if %ha% == n goto lvl1
if %ha% == N goto lvl1
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl1
if %start% == Y goto lvl1
if %start% == n goto menu
if %start% == N goto menu
goto start game
:lvl2
cls
echo Question 2)
echo which planet is the 5th from the sun?
echo a.Venus
echo b.Jupiter
echo c.Uranus
echo d.Earth
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto crl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl2
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl3
if %hi% == Y goto lvl3
if %hi% == n goto lvl2
if %hi% == N goto lvl2
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl2
if %start% == Y goto lvl2
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl3
cls
echo Question 3)
echo which of the following colours has the most pigments?
echo a.Blue
echo b.Orange
echo c.Brown
echo d.Red
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto crl
if %hi% == d goto wrl
goto lvl3
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl4
if %hi% == Y goto lvl4
if %hi% == n goto lvl3
if %hi% == N goto lvl3
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl3
if %start% == Y goto lvl3
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl4
cls
echo Question 4)
echo who was the first man launched in to space?
echo a.Mike Collins
echo b.Neil Armstrong
echo c.Yuri gagarin
echo d.Buzz Aldrin
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto crl
if %hi% == d goto wrl
goto lvl4
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl5
if %hi% == Y goto lvl5
if %hi% == n goto lvl4
if %hi% == N goto lvl4
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl4
if %start% == Y goto lvl4
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl5
cls
echo Question 5)
echo Who was the Original owner of Apple?
echo a.Steve Jobs
echo b.Bill Gates
echo c.Jeorge Lucas
echo d.Harry Potter
set /p hi=
if %hi% == a goto crl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl5
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl6
if %hi% == Y goto lvl6
if %hi% == n goto lvl5
if %hi% == N goto lvl5
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl5
if %start% == Y goto lvl5
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl6
cls
echo Question 6)
echo Which of these deceased singers was assasinated?
echo a. Freddie Mercury
echo b. John Lennon
echo c. Elvis Presley
echo d. Michael Jackson
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto crl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl7
if %hi% == Y goto lvl7
if %hi% == n goto lvl6
if %hi% == N goto lvl6
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl6
if %start% == Y goto lvl6
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl7
cls
echo Question 7)
echo Who created the first light bulb?
echo a. Thomas Edison
echo b. Hiram Stevens
echo c. Joseph Swan
echo d. Albert Einstein
set /p hi=
if %hi% == a goto crl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl8
if %hi% == Y goto lvl8
if %hi% == n goto lvl7
if %hi% == N goto lvl7
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl7
if %start% == Y goto lvl7
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl8
cls
echo Question 8)
echo how old was Sir Edmund Hillary when he died?
echo a. 79
echo b. 92
echo c. 86
echo d. 88
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto crl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl9
if %hi% == Y goto lvl9
if %hi% == n goto lvl8
if %hi% == N goto lvl8
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl8
if %start% == Y goto lvl8
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl9
cls
echo Question 9)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto crl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl10
if %hi% == Y goto lvl10
if %hi% == n goto lvl9
if %hi% == N goto lvl9
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl9
if %start% == Y goto lvl9
if %start% == n goto menu
if %start% == N goto menu
:lvl10
cls
echo Question 10)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto crl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl11
if %hi% == Y goto lvl11
if %hi% == n goto lvl10
if %hi% == N goto lvl10
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl10
if %start% == Y goto lvl10
if %start% == n goto menu
if %start% == N goto menu
:lvl11
cls
echo Question 11)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto crl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl12
if %hi% == Y goto lvl12
if %hi% == n goto lvl11
if %hi% == N goto lvl11
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl11
if %start% == Y goto lvl11
if %start% == n goto menu
if %start% == N goto menu
:lvl12
cls
echo Question 12)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto crl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl13
if %hi% == Y goto lvl13
if %hi% == n goto lvl12
if %hi% == N goto lvl12
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl12
if %start% == Y goto lvl12
if %start% == n goto menu
if %start% == N goto menu
:lvl13
cls
echo Question 13)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto crl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl14
if %hi% == Y goto lvl14
if %hi% == n goto lvl13
if %hi% == N goto lvl13
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl13
if %start% == Y goto lvl13
if %start% == n goto menu
if %start% == N goto menu
:lvl14
cls
echo Question 14)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto crl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl15
if %hi% == Y goto lvl15
if %hi% == n goto lvl14
if %hi% == N goto lvl14
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl14
if %start% == Y goto lvl14
if %start% == n goto menu
if %start% == N goto menu
:lvl15
cls
echo Question 15)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto crl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl16
if %hi% == Y goto lvl16
if %hi% == n goto lvl15
if %hi% == N goto lvl15
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl15
if %start% == Y goto lvl15
if %start% == n goto menu
if %start% == N goto menu
:lvl16
cls
echo Question 16)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto crl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl17
if %hi% == Y goto lvl17
if %hi% == n goto lvl16
if %hi% == N goto lvl16
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl16
if %start% == Y goto lvl16
if %start% == n goto menu
if %start% == N goto menu
:lvl17
cls
echo Question 17)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto crl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl18
if %hi% == Y goto lvl18
if %hi% == n goto lvl17
if %hi% == N goto lvl17
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl17
if %start% == Y goto lvl17
if %start% == n goto menu
if %start% == N goto menu
:lvl18
cls
echo Question 18)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto crl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl19
if %hi% == Y goto lvl19
if %hi% == n goto lvl18
if %hi% == N goto lvl18
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl18
if %start% == Y goto lvl18
if %start% == n goto menu
if %start% == N goto menu
:lvl19
cls
echo Question 19)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto crl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl20
if %hi% == Y goto lvl20
if %hi% == n goto lvl19
if %hi% == N goto lvl19
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl19
if %start% == Y goto lvl19
if %start% == n goto menu
if %start% == N goto menu
:lvl20
cls
echo Question 20)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto crl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct! Thanks For Playing! :)
pause
goto menu
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl20
if %start% == Y goto lvl20
if %start% == n goto menu
if %start% == N goto menu
#echo off
setlocal disableDelayedExpansion
set q=^"
echo(
echo(
call :c 0E " , .-;" /n
call :c 0E " , |\ / / __," /n
call :c 0E " |\ '.`-.| |.'.-'" /n
call :c 0E " \`'-: `; : /" /n
call :c 0E " `-._'. \'|" /n
call :c 0E " ,_.-=` ` ` ~,_" /n
call :c 0E " '--,. "&call :c 0c ".-. "&call :c 0E ",=!q!." /n
call :c 0E " / "&call :c 0c "{ "&call :c 0A "* "&call :c 0c ")"&call :c 0E "`"&call :c 06 ";-."&call :c 0E "}" /n
call :c 0E " | "&call :c 0c "'-' "&call :c 06 "/__ |" /n
call :c 0E " / "&call :c 06 "\_,\|" /n
call :c 0E " | (" /n
call :c 0E " "&call :c 0c "__ "&call :c 0E "/ ' \" /n
call :c 02 " /\_ "&call :c 0c "/,'`"&call :c 0E "| ' "&call :c 0c ".-~!q!~~-." /n
call :c 02 " |`.\_ "&call :c 0c "| "&call :c 0E "/ ' , "&call :c 0c "/ \" /n
call :c 02 " _/ `, \"&call :c 0c "| "&call :c 0E "; , . "&call :c 0c "| , ' . |" /n
call :c 02 " \ `, "&call :c 0c "| "&call :c 0E "| , , "&call :c 0c "| : ; : |" /n
call :c 02 " _\ `, "&call :c 0c "\ "&call :c 0E "|. , "&call :c 0c "| | | | |" /n
call :c 02 " \` `. "&call :c 0c "\ "&call :c 0E "| ' "&call :c 0A "|"&call :c 0c "\_|-'|_,'\|" /n
call :c 02 " _\ `, "&call :c 0A "`"&call :c 0E "\ ' . ' "&call :c 0A "| | | | | "&call :c 02 "__" /n
call :c 02 " \ `, "&call :c 0E "| , ' "&call :c 0A "|_/'-|_\_/ "&call :c 02 "__ ,-;` /" /n
call :c 02 " \ `, "&call :c 0E "\ . , ' .| | | | | "&call :c 02 "_/' ` _=`|" /n
call :c 02 " `\ `, "&call :c 0E "\ , | | | | |"&call :c 02 "_/' .=!q! /" /n
call :c 02 " \` `, "&call :c 0E "`\ \/|,| ;"&call :c 02 "/' .=!q! |" /n
call :c 02 " \ `, "&call :c 0E "`\' , | ; "&call :c 02 "/' =!q! _/" /n
call :c 02 " `\ `, "&call :c 05 ".-!q!!q!-. "&call :c 0E "': "&call :c 02 "/' =!q! /" /n
call :c 02 " _`\ ;"&call :c 05 "_{ ' ; "&call :c 02 "/' =!q! /" /n
call :c 02 " _\`-/__"&call :c 05 ".~ `."&call :c 07 "8"&call :c 05 ".'.!q!`~-. "&call :c 02 "=!q! _,/" /n
call :c 02 " __\ "&call :c 05 "{ '-."&call :c 07 "|"&call :c 05 ".'.--~'`}"&call :c 02 " _/" /n
call :c 02 " \ .=!q!` "&call :c 05 "}.-~!q!'"&call :c 0D "u"&call :c 05 "'-. '-..' "&call :c 02 "__/" /n
call :c 02 " _/ .!q! "&call :c 05 "{ -'.~('-._,.'"&call :c 02 "\_,/" /n
call :c 02 " / .!q! _/'"&call :c 05 "`--; ; `. ;" /n
call :c 02 " .=!q! _/' "&call :c 05 "`-..__,-'" /n
call :c 02 " __/'" /n
echo(
exit /b
:c
setlocal enableDelayedExpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:colorPrint Color Str [/n]
setlocal
set "s=%~2"
call :colorPrintVar %1 s %3
exit /b
:colorPrintVar Color StrVar [/n]
if not defined DEL call :initColorPrint
setlocal enableDelayedExpansion
pushd .
':
cd \
set "s=!%~2!"
:: The single blank line within the following IN() clause is critical - DO NOT REMOVE
for %%n in (^"^
^") do (
set "s=!s:\=%%~n\%%~n!"
set "s=!s:/=%%~n/%%~n!"
set "s=!s::=%%~n:%%~n!"
)
for /f delims^=^ eol^= %%s in ("!s!") do (
if "!" equ "" setlocal disableDelayedExpansion
if %%s==\ (
findstr /a:%~1 "." "\'" nul
<nul set /p "=%DEL%%DEL%%DEL%"
) else if %%s==/ (
findstr /a:%~1 "." "/.\'" nul
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%"
) else (
>colorPrint.txt (echo %%s\..\')
findstr /a:%~1 /f:colorPrint.txt "."
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
)
)
if /i "%~3"=="/n" echo(
popd
exit /b
:initColorPrint
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A"
<nul >"%temp%\'" set /p "=."
subst ': "%temp%" >nul
exit /b
:cleanupColorPrint
2>nul del "%temp%\'"
2>nul del "%temp%\colorPrint.txt"
>nul subst ': /d
exit /b
I need the parrot to load first then the quiz, and every time I try combing them none of what I have tried has worked.
And thank you all before you even answer. So this is my first question in Stackoverflow.com i keep getting an error message saying "goto was unexpected at this time" i've searched for solution but i cant find anything. So if you know what im doing wrong tell me please :) im quite new to batch... im sorry if im doing really noobish mistake but i just cant tell whats wrong.
#echo off
:type
cls
echo %msg1%
echo %order%
choice /C abcdefghijklmnopqrstuvwxyz12 /n
if %errorlevel% == 28 goto save
if %errorlevel% == 27 goto varsave
if %errorlevel% == 26 goto set2
if %errorlevel% == 25 goto set2
if %errorlevel% == 24 goto set2
if %errorlevel% == 23 goto set2
if %errorlevel% == 22 goto set2
if %errorlevel% == 21 goto set2
if %errorlevel% == 20 goto set2
if %errorlevel% == 19 goto set2
if %errorlevel% == 18 goto set2
if %errorlevel% == 17 goto set2
if %errorlevel% == 16 goto set2
if %errorlevel% == 15 goto set2
if %errorlevel% == 14 goto set2
if %errorlevel% == 13 goto set2
if %errorlevel% == 12 goto set2
if %errorlevel% == 11 goto set2
if %errorlevel% == 10 goto set2
if %errorlevel% == 9 goto set
if %errorlevel% == 8 goto set
if %errorlevel% == 7 goto set
if %errorlevel% == 6 goto set
if %errorlevel% == 5 goto set
if %errorlevel% == 4 goto set
if %errorlevel% == 3 goto set
if %errorlevel% == 2 goto set
if %errorlevel% == 1 goto set
The only way to get goto was unexpected is an empty %errorlevel% variable. That should never happen. Are you sure, that you didn't set it manually somewhere in your code (something like set errorlevel=?
As others stated already, your construct with if %errorlevel% == xx should work fine. But you can dramatically shorten your code, because if errorlevel xx really means: "If errorlevel is xx or greater" (not like if %errorlevel% == xx, wich does a string comparison):
#echo off
:type
cls
echo %msg1% echo %order%
choice /C abcdefghijklmnopqrstuvwxyz12 /n
if errorlevel 28 goto save
if errorlevel 27 goto varsave
if errorlevel 10 goto set2
if errorlevel 1 goto set
Try it without the %s around ERRORLEVEL. And remove the ==s.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am almost done with my game and have employed "Alternate Data Streams" to save some high scores in a ADS. Now i tried to do the same with a color option, to make the game be the same color scheme you set it every time you open it until you want to change it. Here is the code that i am working on:
echo.
echo Color Options - background/text
echo ------------------
echo 0) Black
echo 1) Blue
echo 2) green
echo 3) Aqua
echo 4) Red
echo 5) Purple
echo 6) Yellow
echo 7) White
echo 8) Grey
echo ------------------
set /p BcolorSetting=Background:
set /p TcolorSetting=Text:
echo %BcolorSetting%%TcolorSetting% >>"%~f0:colors"
color <"%~f0:colors"
pause
If you want to see the whole thing it's...
#echo off
REM Produced by Calder Hutchins
REM This is a game
title Memory Game
:begin
set point=0
cls
echo.
echo Memeory Game
echo ------------------
echo 1) Play
echo 2) Instructions
echo 3) High Scores
echo 4) Options
echo ------------------
set /p pick=^>
if %pick%==1 goto one
if %pick%==2 goto two
if %pick%==3 goto three
if %pick%==4 goto four
if %pick%==99 goto test
goto begin
:one
cls
REM Determines the number
if %point% LSS 6 set /a rand=%random% %% (100 - 1 + 1)+ 1
if %point% LSS 12 if %point% GTR 5 set /a rand=%random% %% (500 - 100 + 1)+ 100
if %point% LSS 18 if %point% GTR 11 set /a rand=%random% %% (1000 - 500 + 1)+ 500
if %point% LSS 24 if %point% GTR 17 set /a rand=%random% %% (2000 - 1000 + 1)+ 1000
if %point% LSS 30 if %point% GTR 23 set /a rand=%random% %% (9000 - 1500 + 1)+ 1500
if %point% LSS 36 if %point% GTR 29 set /a rand=%random% %% (19000 - 5000 + 1)+ 5000
if %point% LSS 42 if %point% GTR 35 set /a rand=%random% %% (32000 - 10000 + 1)+ 10000
if %point% LSS 48 if %point% GTR 41 set /a rand=%random% %% (999 - 100 + 1)+ 100
if %point% LSS 48 if %point% GTR 41 set /a randtwo=%random% %% (999 - 100 + 1)+ 100
if %point% GTR 47 set /a rand=%random% %% (9999 - 1000 + 1)+ 1000
if %point% GTR 47 set /a randtwo=%random% %% (9999 - 1000 + 1)+ 1000
echo.
REM Prints the number
if %point% LSS 42 echo %rand%
if %point% GTR 41 set rand=%rand%%randtwo%
if %point% GTR 41 echo %rand%
echo.
ping localhost -n 3 >nul
cls
echo.
echo.
echo.
set /p yourOption=Guess:
REM Determines correct or wrong
if %youroption%==%rand% set /a point=%point% +1 & goto one
cls
echo.
echo You scored: %point%
echo.
set /p name=Type name:
echo %name% - %point% >>"%~f0:scores"
goto begin
:two
cls
echo.
echo The objective of the game is to get as many points as possible. To get points you must correctly retype the numbers that appear on the screen. The numbers show for a short period of time. As you get more points the numbers get longer! When you have lost you will be prompted to enter your name. You can view the highscores too!
echo.
pause
goto begin
:three
cls
echo.
more<"%~f0:scores" | sort
echo.
pause
goto begin
:four
cls
echo.
echo Settings/Options
echo ------------------
echo 1) color
echo ------------------
set /p pickSetting=^>
if %pickSetting%==1 goto oneSetting
goto four
:oneSetting
cls
echo.
echo Color Options - background/text
echo ------------------
echo 0) Black
echo 1) Blue
echo 2) green
echo 3) Aqua
echo 4) Red
echo 5) Purple
echo 6) Yellow
echo 7) White
echo 8) Grey
echo ------------------
set /p BcolorSetting=Background:
set /p TcolorSetting=Text:
echo %BcolorSetting%%TcolorSetting% >>"%~f0:colors"
color <"%~f0:colors"
pause
goto begin
Thank-you in advance guys!
Fortunately the FOR /F can read ADS:
for /f "usebackq" %%C in ("%~f0:colors") do COLOR %%C
It appears that you will have to CD a certain directory. Then, write to a text file within the directory. In the start, read the text file.
Then, overwrite the text file and write the color in it at the point you are stuck in.
If you need to start with settings in any app, you always need a save file.
Writing can be like this:
echo %BcolorSetting%%TcolorSetting% >>"colorsetting.txt"
And when retrieving, do it in the very beginning. Before begin.
It is read like this
set /p %~f0:colors= <colorsetting.txt
Assuming you use those variables. I hope this helps.