#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
Related
I am made a CMD batch file to generate the barcode numbers. Batch script generate the last ninth number of barcode by doing the calculation and generate the file named "barcode.txt". The code is working fine. Only the problem is when the "fn" number "Barcode Eight Digit " start with zero then the code is not working properly.
#echo off
setlocal EnableDelayedExpansion
set /p al=Please enter Alfa two digit:
set /p fn=Please enter Barcode Eight Digit:
set /p no=Please enter number of Barode:
set /a NUMBER=%fn%
set /a to=%no%
set /a count=1
pause
:loop
if %count% GTR %to% GOTO :end
set var1=%NUMBER:~0, 1%
set var2=%NUMBER:~1, 1%
set var3=%NUMBER:~2, 1%
set var4=%NUMBER:~3, 1%
set var5=%NUMBER:~4, 1%
set var6=%NUMBER:~5, 1%
set var7=%NUMBER:~6, 1%
set var8=%NUMBER:~7, 1%
set /A B1 = %var1% * 8
set /A B2 = %var2% * 6
set /A B3 = %var3% * 4
set /A B4 = %var4% * 2
set /A B5 = %var5% * 3
set /A B6 = %var6% * 5
set /A B7 = %var7% * 9
set /A B8 = %var8% * 7
set /A B9 = %B1% + %B2% + %B3% + %B4% + %B5% + %B6% + %B7% + %B8%
set /A B10 = (%B9%) %% 11
set /A B11 = 11- %B10%
if "%B11%"=="10" (set B11=0)
if "%B11%"=="11" (set B11=5)
echo %al%%NUMBER%%B11%IN >> barcode.txt
set /a NUMBER+=1
set /a count+=1
goto loop
:end
echo end it
pause
I tried to find the solution but failed. Can please any one help me to fix the issue while number start with zero.
Use
set /a NUMBER=%fn% + 100000000
(1 followed by 8 0s)
Then
echo %al%%NUMBER:~1%%B11%IN >> barcode.txt
Thanks to suggest me. I have made the working code by just declaring set /a NUMBER=1%fn%.
#echo off
setlocal EnableDelayedExpansion
set /p al=Please enter Alfa two digit:
set /p fn=Please enter Barcode Eight Digit:
set /p no=Please enter number of Barode:
set /a NUMBER=1%fn%
set to=%no%
set count=1
pause
:loop
if %count% GTR %to% GOTO :end
set var1=%NUMBER:~1, 1%
set var2=%NUMBER:~2, 1%
set var3=%NUMBER:~3, 1%
set var4=%NUMBER:~4, 1%
set var5=%NUMBER:~5, 1%
set var6=%NUMBER:~6, 1%
set var7=%NUMBER:~7, 1%
set var8=%NUMBER:~8, 1%
set /A B1 = var1 * 8
set /A B2 = var2 * 6
set /A B3 = var3 * 4
set /A B4 = var4 * 2
set /A B5 = var5 * 3
set /A B6 = var6 * 5
set /A B7 = var7 * 9
set /A B8 = var8 * 7
set /A B9 = B1 + B2 + B3 + B4 + B5 + B6 + B7 + B8
set /A B10 = B9 %% 11
set /A B11 = 11- B10
if "%B11%"=="10" (set B11=0)
if "%B11%"=="11" (set B11=5)
echo %al%%NUMBER:~1%%B11%IN >> barcode.txt
set /a NUMBER+=1
set /a count+=1
goto loop
:end
echo end it
pause
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
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.