-2

i need help combining "if" and "set" because im making myself a register at school because im bored

the problem i need help with is at the bottom of the page.

here is my code:

:start
@echo off
color b5
title Register
echo welcome! :)
pause
goto :icn

:icn
cls
echo Is Callum Shevlin in?
echo.
echo 1) in
echo 2) out

set /p icnn=
if %icnn%==1 set /a %icnnn%== "in"
if %icnn%==2 set /a %icnnn%== "out"
goto :ici

:ici
cls
echo Is Charlie Davies in?
echo.
echo 1) in
echo 2) out

set /p icnn2=
if %icnn2%==1 set /a %icnn22%== "in"
if %icnn2%==2 set /a %icnn22%== "out"
goto :icin

:icin
cls
echo Is Joshua Glover in?
echo.
echo 1) in
echo 2) out

set /p icnnii=
if %icnnii%==1 set /a %icnniii%== "in"
if %icnnii%==2 set /a %icnniii%== "out"
goto :icint

:icint
cls
echo Is Blake Harrison-Akers in?
echo.
echo 1) in
echo 2) out

set /p icnnttii=
if %icnnttii%==1 set /a %icnntttii%== "in"
if %icnnttii%==2 set /a %icnntttii%== "out"
goto :icie

:icie
cls
echo Is Reece Radford in?
echo.
echo 1) in
echo 2) out

set /p ikki=
if %ikki%==1 set /a %ikkii%== "in"
if %ikki%==2 set /a %ikkii%== "out"
goto :icikkkik

:icikkkik
cls
echo Is Chris Martin in?
echo.
echo 1) in
echo 2) out

set /p kollo=
if %kollo%==1 set /a %kolloo%== "in"
if %kollo%==2 set /a %kolloo%== "out"
goto :results

:results
cls
echo --------------------
echo Callum Shevlin = %icnnn%
echo -----------------------
echo Charlie Davies = %icnn22%
echo ----------------------
echo Joshua Glover = %icnniii%
echo ------------------------------
echo Blake Harrison-Akers = %icnnttt%
echo ---------------------
echo Recce Radford = %ikkii%
echo --------------------
echo Chris Martin = %kolloo%
echo ---------------------
pause
goto :start

but the problem is after you have gotten to the results page it displays no text after the "=" signs

i want to know whats wrong.

  • You are not using the `set` command correctly... You want to do `set "icnnn=in"`, with only one equals sign, for example, not `set %icnnn%== "in"`. Avoid spaces before and after the equals sign. Put double quotes around the full command instead, Like `set "myVar=myValue"`(`set "icnn=in"`), so you can see unwanted spaces. More at `set /?.` – Daniel Luz May 20 '16 at 14:55
  • Please read [Why is no string output with 'echo %var%' after using 'set var = text' on command line?](http://stackoverflow.com/a/26388460/3074564) for a detailed explanation of made mistakes on assigning a string to a variable. And read also answer on [Call batch within batch?](http://stackoverflow.com/a/37226895/3074564) demonstrating error checking for invalid input because of using `set /P` for letting the batch user enter a number from predefined options. And everything after `set /A` is interpreted as arithmetic expression. Therefore use `set /a` only for arithmetic expressions. – Mofi May 21 '16 at 14:31
  • Thx, :D. it really helped! – blake harrisonakerz May 26 '16 at 10:26
  • but also the thing is, when ive made my .bat rpg games in the past, "==" worked fine, how come it dosent work all of a sudden? – blake harrisonakerz May 26 '16 at 10:29

1 Answers1

0

As @DanielLuz said, you used set wrong. The following is your script fixed:

:start
@echo off
color b5
title Register
echo welcome! :)
pause
goto :icn

:icn
cls
echo Is Callum Shevlin in?
echo.
echo 1) in
echo 2) out

set /p icnn=
if %icnn%==1 set "icnnn=in"
if %icnn%==2 set "icnnn=out"
goto :ici

:ici
cls
echo Is Charlie Davies in?
echo.
echo 1) in
echo 2) out

set /p icnn2=
if %icnn2%==1 set "icnn22%=in"
if %icnn2%==2 set "icnn22%=out"
goto :icin

:icin
cls
echo Is Joshua Glover in?
echo.
echo 1) in
echo 2) out

set /p icnnii=
if %icnnii%==1 set "icnniii=in"
if %icnnii%==2 set "icnniii=out"
goto :icint

:icint
cls
echo Is Blake Harrison-Akers in?
echo.
echo 1) in
echo 2) out

set /p icnnttii=
if %icnnttii%==1 set "icnntttii=in"
if %icnnttii%==2 set "icnntttii=out"
goto :icie

:icie
cls
echo Is Reece Radford in?
echo.
echo 1) in
echo 2) out

set /p ikki=
if %ikki%==1 set "ikkii=in"
if %ikki%==2 set "ikkii=out"
goto :icikkkik

:icikkkik
cls
echo Is Chris Martin in?
echo.
echo 1) in
echo 2) out

set /p kollo=
if %kollo%==1 set "kolloo=in"
if %kollo%==2 set "kolloo=out"
goto :results

:results
cls
echo --------------------
echo Callum Shevlin = %icnnn%
echo -----------------------
echo Charlie Davies = %icnn22%
echo ----------------------
echo Joshua Glover = %icnniii%
echo ------------------------------
echo Blake Harrison-Akers = %icnnttt%
echo ---------------------
echo Recce Radford = %ikkii%
echo --------------------
echo Chris Martin = %kolloo%
echo ---------------------
pause
goto :start

Also, you would be better off using the choice command. Replace all instances of set /p and your ifs to the following example (of course, you should change it to use the correct variable):

choice /c 12 /n >nul
if %errorlevel% == 1 set "VARIABLEHERE=in"
if %errorlevel% == 2 set "VARIABLEHERE=out"

More info can be found with choice /?.

Matthew Horvath
  • 186
  • 1
  • 12