Jump to content

Batch Scripting Error: How do I allow a user playing my game switch the colors of the game itself via a menu?

Basically, what I'm interested in doing, is allow the user playing my game, through a settings menu, switch the colors of the text in game ( and in the menu ). If you run my code, and you select a color via settings/color settings/ from the main menu, it will select the color correctly, however once you exit the color settings menu. It will revert the color to purple or some odd reason, and not the color you selected. How do I fix this? Here is the code...

@echo off
title KnightsOval 
cls
title RPG Game
color e
mode 80,25
goto titlescreen
:titlescreen
if "%color%"=="1" ( set "%color%"="e")
      if "%color%"=="2" ( set "%color%"="07")
if "%color%"=="3" ( set "%color%"="03")
      if "%color%"=="4" ( set "%color%"="0c")
color %color%
cls
echo.
echo                                       ======
echo                                     Welcome To
echo                                     KnightRealm
echo                                       ======
echo.
echo                                     [1] =Play=
echo                                     [2] =Settings=
echo                                     [3] =Exit=
echo.
echo   Made by: MS-DOS Guy
echo  ===============================================================================
set /p selection1=">" 
if /i "%selection1%"=="1" goto StartGame
if /i "%selection1%"=="2" goto Settings
if /i "%selection1%"=="3" exit

:StartGame

cls
echo.
echo.
echo.
echo.
echo                            Far away...
color 01
ping 127.0.0.1 -n 4 > nul 
cls
echo.
echo    In a Land...
color 02
ping 127.0.0.1 -n 4 > nul      
cls    
echo.
echo.
echo                                        Considered to be one of the most 
color 03
ping 127.0.0.1 -n 5 > nul
cls   
echo.
echo.
echo.
echo.
echo.
echo.
echo.     
echo            Dangerous, and Bandit filled Lands
color 04
ping 127.0.0.1 -n 4 > nul
echo Lies a man, a man seeking to fix humanity's evil doers, and regain peace 
echo and order in the world...
ping 127.0.0.1 -n 4 > nul 
cls
echo             This man's name is
ping 127.0.0.1 -n 2 > nul
cls
echo             This man's name is.
ping 127.0.0.1 -n 3 > nul
cls
echo             This man's name is..
ping 127.0.0.1 -n 3 > nul
cls
ping 127.0.0.1 -n 3 > nul
cls 
echo             This man's name is...
ping 127.0.0.1 -n 2 > nul
cls
echo Ehhh, what is your name young boy? 
echo.
echo.
set /p name="Enter Your Name:"
cls
echo  Ah, good! I see your name is %name%, very nice name, has a nice 
echo  ring to it I suppose. Now! If I may ask, haha, it looks like
echo  I have forgotten your class! 
echo.
echo.
echo ===============================================================
echo  SELECT YOUR CLASS --------------------------------------------
echo ===============================================================
echo  = WARLOCK =
echo.
echo.
echo  = ROGUE =
echo.
echo.
echo  = TITAN =
echo.
set /p class="Enter Your Class:"
if "%class%"=="Warlock" goto next1 
    )
    if "%class%"=="Titan" goto next1  
    )
if "%class%"=="Rogue" goto next1 
    )
goto exit 
:color c0
echo PICK A CORRECT CHOICE/COMMAND! 
echo.
echo Redo Y/N? 
goto startgame 
exit 
:next1
if "%color%"=="1" ( set "%color%"="e")
      if "%color%"=="2" ( set "%color%"="07")
if "%color%"=="3" ( set "%color%"="03")
      if "%color%"=="4" ( set "%color%"="0c")
      color %color%
cls
echo  I could have sworn your class was %class%! Sounds about right!
ping 127.0.0.1 -n 4 > nul
cls
echo  Unknown: Eh, anyways, I suppose now its time I introduce who I may be...
echo ================================================================
echo  1) Yeah, who are you?
echo.
echo  2) No, let me embark on my quest! 
echo.
echo ================================================================
set /p choice1=">"
if "%choice1%"=="1" goto continuestory1
if "%choice1%"=="2" goto continuestory2 
:continuestory1
if "%color%"=="1" ( set "%color%"="e")
      if "%color%"=="2" ( set "%color%"="07")
if "%color%"=="3" ( set "%color%"="03")
      if "%color%"=="4" ( set "%color%"="0c")
      color %color%
cls
echo Unknown: Well... I'm glad you asked
ping 127.0.0.1 -n 4 > nul 
goto continuestory3
:continuestory3
color %color%
echo.
echo.
echo.
echo                                      ....
echo                                .'' .'''
echo                              .'   :
echo   \\                          .:    :
echo    \\                        _:    :       ..----.._
echo     \\                    .:::.....:::.. .'         ''.
echo      \\                 .'  #-. .-######'     #        '.
echo       \\                 '.##'/ ' ################       :
echo        \\                  #####################         :
echo         \\               ..##.-.#### .''''###'.._        :
echo          \\             :--:########:            '.    .' :
echo           \\..__...--.. :--:#######.'   '.         '.     :
echo           :     :  : : '':'-:'':'::        .         '.  .'
echo           '---'''..: :    ':    '..'''.      '.        :'
echo              \\  :: : :     '      ''''''.     '.      .:
echo               \\ ::  : :     '            '.      '      :
echo                \\::   : :           ....' ..:       '     '.
echo                 \\::  : :    .....####\\ .~~.:.             :
echo                  \\':.:.:.:'#########.  =. ~ .'-.   . '''.. :
echo                   \\    .'  ########## \ \ _.' '. '-.       '''.
echo                   :\\  :     ########   \ \      '.  '-.        :
echo                  :  \\'    '   #### :    \ \      :.    '-.      :
echo                 :  .'\\   :'  :     :     \ \       :      '-.    :
echo                : .'  .\\  '  :      :     :\ \       :        '.   :
echo                ::   :  \\'  :.      :     : \ \      :          '. :
echo                ::. :    \\  : :      :    ;  \ \     :           '.:
echo                 : ':    '\\ :  :     :     :  \:\     :        ..'
echo                    :    ' \\ :        :     ;  \       :   .'''
echo                    '.   '  \\:                         :.''
echo                     .:..... \\:       :            ..''
echo                    '._____ '.\\......'''''''.:..'''
echo                               \\
echo.
echo ==============================================================
echo  Ralph: My name is Ralph, how rude of me, to now inform you 
echo  at such a time, %name%! Now, let me show you outside!
echo ==============================================================
echo  [1] - Sure, Ralph. 
echo  [2] - Where am I, right now? 
echo  []
echo.
echo.
echo.
pause




:continuestory2
cls
echo  Unknown: Well too bad! I was going to tell you anyways!
ping 127.0.0.1 -n 5 > nul
goto continuestory3





:Settings
if "%color%"=="1" ( set "%color%"="e")
      if "%color%"=="2" ( set "%color%"="07")
if "%color%"=="3" ( set "%color%"="03")
      if "%color%"=="4" ( set "%color%"="0c")
cls
color %color%
echo                                    ======
echo                                   Settings 
echo                                    ======
echo.
echo                                  [1] =Display Settings=
echo                                  [2] =Color Settings=
echo                                  
echo.
echo                                  [3] =Go Back=
echo.
echo ===============================================================================
set /p settings=">"
if /i "%settings%"=="1" goto DisplaySeti
if /i "%settings%"=="2" goto ColorS
if /i "%settings%"=="3" goto titlescreen 




:DisplaySeti
if "%color%"=="1" ( set "%color%"="e")
      if "%color%"=="2" ( set "%color%"="07")
if "%color%"=="3" ( set "%color%"="03")
      if "%color%"=="4" ( set "%color%"="0c")
      color %color%
cls
echo ====================
echo Display Settings
echo ====================
echo 1) Default
echo 2) Fullscreen
echo 3) Back
set /p displayseti=">"
if "%displayseti%"=="1" mode 80,25
if "%displayseti%"=="2" mode con: cols=160 lines=78
if "%displayseti%"=="3" goto settings 

goto DisplaySeti
:ColorS
if "%color%"=="1" ( set "%color%"="e")
      if "%color%"=="2" ( set "%color%"="07")
if "%color%"=="3" ( set "%color%"="03")
      if "%color%"=="4" ( set "%color%"="0c")
      color %color%
cls
echo ====================
echo Color Settings
echo ====================
echo 1) Yellow ( Default )
echo 2) White 
echo 3) Blue
echo 4) Red
echo ===================
echo 5) Go Back
echo ===================
set /p color=">"
if "%color%"=="1" color 0e
if "%color%"=="2" color 07
if "%color%"=="3" color 03
if "%color%"=="4" color 0c
if "%color%"=="5" goto settings
      rem switching variables to match color code
if "%color%"=="1" ( set "%color%"="e")
      if "%color%"=="2" ( set "%color%"="07")
if "%color%"=="3" ( set "%color%"="03")
      if "%color%"=="4" ( set "%color%"="0c")




goto ColorS

The color selector thingy is located in :ColorS and the code I'm using to make it so that wherever you are in the program, is selected to the color you wanted is "color %color%" but it doesn't seem to work...

My Rig: 

CPU: Intel i5 2500k 4 Cores, 4 Threads @ 4.5ghz ( asus uefi regulates BIOS and adjusts it, there is no manual option, so I can't get any higher than 4.5, but I theoretically should be able to get higher once I get a voltage "changeable" mobo

MOBO: Asus P8Z68 LE

RAM: Kingston HyperX Predator 2133mhz ddr3 2x8 16GB

GPU: GTX 980 TI 150+ core, 100-150 ( I forgot )+ mem ( OC ) 

HDD: 500GB 3D MLC Samsung SSD ( soon ) + 2tb 7200rpm Seagate Constellation ES.2 SAS / LSI MegaRaid MR Raid/SAS Controller

CASE: Phanteks P350X

OS: Windows 10 64-bit / Void Linux 

PERIPHERALS: IBM Model M 1984, Logitech G703 Mouse, Logitech G502 Mouse, Philips SHP9500 w/ V-Moda Boom Pro hooked up to my Sony AMP ( forgot model name, to lazy to find out ) 

 

 

 

Laptop: Gateway P-7805u FX 

CPU: 2.26GHz Intel Core 2 Duo P8400 2c/2t

RAM: 8GB DDR2 1066mhz sodimm 

GPU: Nvidia GeForce 9800M GTS

HDD: 320GB 7200rpm hard drive 2.5"

SSD: Kingston A400 250GB SSD

SCREEN: Glossy 16:9 1440x900

OS: Windows XP SP3 / Ubuntu 19.04

PERIPHERALSLogitech G Pro

Link to comment
Share on other sites

Link to post
Share on other sites

23 minutes ago, MS-DOS Guy said:

ping 127.0.0.1 -n 4 > nul

 

...if you're running this on anything more recent than Windows XP you should use the timeout command.

 

Also it would make a lot more sense if instead of using a hundred echo commands you wrote your story text in dedicated txt files and displayed their contents when appropriate.

34 minutes ago, MS-DOS Guy said:

:ColorS
    if "%color%"=="1" ( set "%color%"="e")
    if "%color%"=="2" ( set "%color%"="07")
    if "%color%"=="3" ( set "%color%"="03")
    if "%color%"=="4" ( set "%color%"="0c")

 

You should really avoid

1) using the same variable for the selection and to hold the color value

2) naming a variable like a command

 

The actual problem here is that you're not actually assigning a new value to the variable color here. The correct command for that would be

set color=e

while

set "%color%"="e"

doesn't actually do anything. Therefore when you run

color %color%

you're running the command color with whatever number the user input, e.g. 5 which is purple. Try it yourself in a terminal.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

18 minutes ago, Sauron said:

...if you're running this on anything more recent than Windows XP you should use the timeout command.

 

Also it would make a lot more sense if instead of using a hundred echo commands you wrote your story text in dedicated txt files and displayed their contents when appropriate.

You should really avoid

1) using the same variable for the selection and to hold the color value

2) naming a variable like a command

 

The actual problem here is that you're not actually assigning a new value to the variable color here. The correct command for that would be


set color=e

while


set "%color%"="e"

doesn't actually do anything. Therefore when you run


color %color%

you're running the command color with whatever number the user input, e.g. 5 which is purple. Try it yourself in a terminal.

Thank you very much!

My Rig: 

CPU: Intel i5 2500k 4 Cores, 4 Threads @ 4.5ghz ( asus uefi regulates BIOS and adjusts it, there is no manual option, so I can't get any higher than 4.5, but I theoretically should be able to get higher once I get a voltage "changeable" mobo

MOBO: Asus P8Z68 LE

RAM: Kingston HyperX Predator 2133mhz ddr3 2x8 16GB

GPU: GTX 980 TI 150+ core, 100-150 ( I forgot )+ mem ( OC ) 

HDD: 500GB 3D MLC Samsung SSD ( soon ) + 2tb 7200rpm Seagate Constellation ES.2 SAS / LSI MegaRaid MR Raid/SAS Controller

CASE: Phanteks P350X

OS: Windows 10 64-bit / Void Linux 

PERIPHERALS: IBM Model M 1984, Logitech G703 Mouse, Logitech G502 Mouse, Philips SHP9500 w/ V-Moda Boom Pro hooked up to my Sony AMP ( forgot model name, to lazy to find out ) 

 

 

 

Laptop: Gateway P-7805u FX 

CPU: 2.26GHz Intel Core 2 Duo P8400 2c/2t

RAM: 8GB DDR2 1066mhz sodimm 

GPU: Nvidia GeForce 9800M GTS

HDD: 320GB 7200rpm hard drive 2.5"

SSD: Kingston A400 250GB SSD

SCREEN: Glossy 16:9 1440x900

OS: Windows XP SP3 / Ubuntu 19.04

PERIPHERALSLogitech G Pro

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, MS-DOS Guy said:

Thank you very much!

If it solved your problem you should close the topic ;)

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×