Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2018-01-14 15:56:51, last edited by TundrumMax (2018-01-14 17:35:44)

TundrumMax
Formerly Memomemo
Joined: 2017-10-26
Posts: 447

Help with batch code

I'm fairly new to coding, so don't expect me to know as much as you would, but I need help
The thing is, the %player% variable don't seem to work as intended, even though in the video i learned batch from it worked completely fine
can you help me out?

@echo off
title Quiz of randomness
color 0a

:menu
cls
title le menu
color 0a
echo Welcome, to the Quiz of randomness
echo ----------------------------------
pause
echo From here you can do some stuff i guess
echo.
echo 1. Start
echo 2. Info
echo 3. Exit
echo.
pause

set /p menuchoice=

if %menuchoice% == 1 goto startgame

if %menuchoice% == 2 goto info

if %menuchoice% == 3 exit
goto menu

:info
cls 
title Info on stuff
color 0b

echo This quiz was made on the 14th of January 2018
echo This quiz is also the first program I have ever made
pause
cls
goto menu
:startgame
cls
title The actual quiz...
color 1a
echo Please enter your name please
echo.

set /p player=
echo.
echo Press any key to start the quiz
pause >nul
goto q1

:q1
cls
title Question 1
cls
echo Question 1
echo ----------
echo.
echo What is 1 + 1?
echo.
echo A) 2
echo B) 11
echo C) window
echo.

set /p ans1=
if %ans1% == a goto cr1
if %ans1% == b goto wr1
if %ans1% == c goto wr1
goto q1

:wr1
cls
title You lost... :(
color 8f
echo Sorry %player%, you lost...
echo.
echo Press any key to return to the menu
pause >nul
goto menu

:cr1
cls
title You are correct I guess
color 9a
echo Congrats %player% you got that one question correct
echo.
echo Press any key to continue...
pause >nul
goto q2

:q2
cls
title Question 2
cls
echo Question 2
echo ----------
echo.
echo How many inches are in a foot
echo.
echo A) 15
echo B) 12
echo C) window
echo.

set /p ans2=
if %ans2% == a goto wr1
if %ans2% == b goto cr2
if %ans2% == c goto wr1
goto q2


:cr2
cls
title You are correct again, wow
color 9a
echo Congrats %player% you got that other question correct, im surprised you didnt choose
echo window again...
echo.
echo Press any key to continue...
pause >nul
goto q3

:q3
cls
title Question 3
cls
echo Question 3
echo ----------
echo.
echo What is the capital of Britain
echo.
echo A) London
echo B) New York
echo C) window
echo.

set /p ans3=
if %ans3% == a goto cr3
if %ans3% == b goto wr1
if %ans3% == c goto wr1
goto q3


:cr3
cls
title You are correct yet again, wow
color 9a
echo Congrats %player% you are doing very well
echo.
echo Press any key to continue...
pause >nul
goto q4

:q4
cls
title Question 4
cls
echo Question 4
echo ----------
echo.
echo What is the creators username on the internet?
echo.
echo A) Bob
echo B) Memomemo
echo C) TundrumMax
echo.

set /p ans4=
if %ans4% == a goto wr1
if %ans4% == b goto wr1
if %ans4% == c goto cr4
goto q4


:cr4
cls
title woot!
color 9a
echo You are almost there!
echo.
echo Press any key to continue...
pause >nul
goto q5

:q5
cls
title Question 5
cls
echo Question 5
echo ----------
echo.
echo What's my favourite colour
echo.
echo A) Blue
echo B) Red
echo C) Purple
echo.

set /p ans5=
if %ans5% == a goto wr1
if %ans5% == b goto wr1
if %ans5% == c goto win
goto q5


:win
cls
title You have won this quiz!
color 0a
ping localhost -n 1
color 0b
ping localhost -n 1
color 0c
ping localhost -n 1
color 0d
ping localhost -n 1
color 0e
ping localhost -n 1
color 0f
cls
echo.
echo                 Well done %player%! You have finished the quiz!
echo.
echo                                Im so proud....
echo.
pause
cls
echo Return to menu? (y/n)
set /p rtrntmenu=

if %rtrntmenu% == y goto menu
if %rtrntmenu% == n exit
goto win

exit

I can speak by breathing in but it sounds like a dying horse

TundrumMax.png

Signature by HG

Offline

#2 2018-01-14 16:19:04

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Help with batch code

I haven't used batch files recently, but could it be that you have a space between player and =? The other set didn't have one and from what you say it seems to work

Offline

#3 2018-01-14 17:26:40

TundrumMax
Formerly Memomemo
Joined: 2017-10-26
Posts: 447

Re: Help with batch code

LukeM wrote:

I haven't used batch files recently, but could it be that you have a space between player and =? The other set didn't have one and from what you say it seems to work

sorry for late reply, i removed the space and somehow it worked


I can speak by breathing in but it sounds like a dying horse

TundrumMax.png

Signature by HG

Offline

Wooted by:

#4 2018-01-14 18:35:42

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Help with batch code

Just got back to my computer so did some fiddling to see why this is. It seems like bat files allow variables with spaces, so the following code works:

@echo off
set /p test =Test: 
echo %test %
pause

This means that if you have the space, you are instead setting the value of a variable called "test ", and when you later try to use the variable "test" it wont have a value

Offline

#5 2018-01-14 19:04:31

TundrumMax
Formerly Memomemo
Joined: 2017-10-26
Posts: 447

Re: Help with batch code

thank you


I can speak by breathing in but it sounds like a dying horse

TundrumMax.png

Signature by HG

Offline

#6 2018-01-15 10:35:14

TundrumMax
Formerly Memomemo
Joined: 2017-10-26
Posts: 447

Re: Help with batch code

ok how do I make timeout go for 0.1 seconds


I can speak by breathing in but it sounds like a dying horse

TundrumMax.png

Signature by HG

Offline

TundrumMax1516008914692464

Board footer

Powered by FluxBB

[ Started around 1711718688.6676 - Generated in 0.040 seconds, 12 queries executed - Memory usage: 1.41 MiB (Peak: 1.52 MiB) ]