Help with score system
Moderator: DosItHelp
-
- Posts: 3
- Joined: 19 Sep 2014 20:11
Help with score system
The score wont update when the answer is correct and the points are added
@echo off
title Guess the number!
color 04
:start
cls
set /a number=(%random% %%15)+1
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
set /a score= 0
echo Score: %score%
echo %number%
echo.
echo - First attempt
echo.
set /P guess=- Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect!
if "%guess%" EQU "%number%" echo - You are correct!
if "%guess%" EQU "%number%" set /a score=score=%score%+10
if %guess% GTR %number% echo - Too high!
if %guess% LSS %number% echo - Too low!
pause
if "%guess%" NEQ "%number%" goto :second
if "%guess%" EQU "%number%" goto :start
:second
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo.
echo - Second attempt
echo.
set /P guess=Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect!
if "%guess%" EQU "%number%" echo - You are correct!
if "%guess%" GTR "%number%" echo - Too high!
if "%guess%" LSS "%number%" echo - Too low!
pause
if "%guess%" EQU "%number%" goto :start
if "%guess%" NEQ "%number%" goto :third
:third
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo.
echo - Final attempt
echo.
set /P guess=- Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect! You have no more attempts!
echo.
if "%guess%" NEQ "%number%" echo - The correct answer is %number%
if "%guess%" EQU "%number%" echo - You are correct!
pause
if "%guess%" EQU "%number%" goto :start
if "%guess%" NEQ "%number%" goto :start
@echo off
title Guess the number!
color 04
:start
cls
set /a number=(%random% %%15)+1
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
set /a score= 0
echo Score: %score%
echo %number%
echo.
echo - First attempt
echo.
set /P guess=- Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect!
if "%guess%" EQU "%number%" echo - You are correct!
if "%guess%" EQU "%number%" set /a score=score=%score%+10
if %guess% GTR %number% echo - Too high!
if %guess% LSS %number% echo - Too low!
pause
if "%guess%" NEQ "%number%" goto :second
if "%guess%" EQU "%number%" goto :start
:second
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo.
echo - Second attempt
echo.
set /P guess=Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect!
if "%guess%" EQU "%number%" echo - You are correct!
if "%guess%" GTR "%number%" echo - Too high!
if "%guess%" LSS "%number%" echo - Too low!
pause
if "%guess%" EQU "%number%" goto :start
if "%guess%" NEQ "%number%" goto :third
:third
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo.
echo - Final attempt
echo.
set /P guess=- Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect! You have no more attempts!
echo.
if "%guess%" NEQ "%number%" echo - The correct answer is %number%
if "%guess%" EQU "%number%" echo - You are correct!
pause
if "%guess%" EQU "%number%" goto :start
if "%guess%" NEQ "%number%" goto :start
Re: Help with score system
Change this
to this
Code: Select all
if "%guess%" EQU "%number%" set /a score=score=%score%+10
to this
Code: Select all
if "%guess%" EQU "%number%" set /a score=score+10
-
- Posts: 3
- Joined: 19 Sep 2014 20:11
Re: Help with score system
foxidrive wrote:Change thisCode: Select all
if "%guess%" EQU "%number%" set /a score=score=%score%+10
to thisCode: Select all
if "%guess%" EQU "%number%" set /a score=score+10
didnt work unfortunately
Re: Help with score system
KrunkJuice101 wrote:didnt work unfortunately
It certainly works to fix that syntax issue.
You really shouldn't initialise the score to zero before you print it though.
Re: Help with score system
ok i tested your code and now is works fine
foxdrive was correct bytheway!
also you can just use
set score=0
you dont need /a when you are giving a value to var without operation(+,-,%,...)
@echo off
title Guess the number!
color 04
set score= 0
:start
cls
set /a number=(%random% %%15)+1
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo %number%
echo.
echo - First attempt
echo.
set /P guess=- Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect!
if "%guess%" EQU "%number%" echo - You are correct!
if "%guess%" EQU "%number%" set /a score=%score%+10
if %guess% GTR %number% echo - Too high!
if %guess% LSS %number% echo - Too low!
pause
if "%guess%" NEQ "%number%" goto :second
if "%guess%" EQU "%number%" goto :start
:second
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo.
echo - Second attempt
echo.
set /P guess=Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect!
if "%guess%" EQU "%number%" echo - You are correct!
if "%guess%" GTR "%number%" echo - Too high!
if "%guess%" LSS "%number%" echo - Too low!
pause
if "%guess%" EQU "%number%" goto :start
if "%guess%" NEQ "%number%" goto :third
:third
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo.
echo - Final attempt
echo.
set /P guess=- Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect! You have no more attempts!
echo.
if "%guess%" NEQ "%number%" echo - The correct answer is %number%
if "%guess%" EQU "%number%" echo - You are correct!
pause
if "%guess%" EQU "%number%" goto :start
if "%guess%" NEQ "%number%" goto :start
foxdrive was correct bytheway!
also you can just use
set score=0
you dont need /a when you are giving a value to var without operation(+,-,%,...)
@echo off
title Guess the number!
color 04
set score= 0
:start
cls
set /a number=(%random% %%15)+1
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo %number%
echo.
echo - First attempt
echo.
set /P guess=- Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect!
if "%guess%" EQU "%number%" echo - You are correct!
if "%guess%" EQU "%number%" set /a score=%score%+10
if %guess% GTR %number% echo - Too high!
if %guess% LSS %number% echo - Too low!
pause
if "%guess%" NEQ "%number%" goto :second
if "%guess%" EQU "%number%" goto :start
:second
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo.
echo - Second attempt
echo.
set /P guess=Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect!
if "%guess%" EQU "%number%" echo - You are correct!
if "%guess%" GTR "%number%" echo - Too high!
if "%guess%" LSS "%number%" echo - Too low!
pause
if "%guess%" EQU "%number%" goto :start
if "%guess%" NEQ "%number%" goto :third
:third
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo.
echo - Final attempt
echo.
set /P guess=- Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect! You have no more attempts!
echo.
if "%guess%" NEQ "%number%" echo - The correct answer is %number%
if "%guess%" EQU "%number%" echo - You are correct!
pause
if "%guess%" EQU "%number%" goto :start
if "%guess%" NEQ "%number%" goto :start
-
- Posts: 3
- Joined: 19 Sep 2014 20:11
Re: Help with score system
Its still not working. I believe the score on the variable is updating, but it wont update on the top of the screen. It stays at 0 but when I echo it after the score it shows the 10 points were added. Another issue with is is the line to check if the number you guessed is too high or low. Sometimes it will say too high when I put like 4, then the answer ends up being 12.
tcpman wrote:ok i tested your code and now is works fine
foxdrive was correct bytheway!
also you can just use
set score=0
you dont need /a when you are giving a value to var without operation(+,-,%,...)
@echo off
title Guess the number!
color 04
set score= 0
:start
cls
set /a number=(%random% %%15)+1
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo %number%
echo.
echo - First attempt
echo.
set /P guess=- Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect!
if "%guess%" EQU "%number%" echo - You are correct!
if "%guess%" EQU "%number%" set /a score=%score%+10
if %guess% GTR %number% echo - Too high!
if %guess% LSS %number% echo - Too low!
pause
if "%guess%" NEQ "%number%" goto :second
if "%guess%" EQU "%number%" goto :start
:second
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo.
echo - Second attempt
echo.
set /P guess=Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect!
if "%guess%" EQU "%number%" echo - You are correct!
if "%guess%" GTR "%number%" echo - Too high!
if "%guess%" LSS "%number%" echo - Too low!
pause
if "%guess%" EQU "%number%" goto :start
if "%guess%" NEQ "%number%" goto :third
:third
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo.
echo - Final attempt
echo.
set /P guess=- Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect! You have no more attempts!
echo.
if "%guess%" NEQ "%number%" echo - The correct answer is %number%
if "%guess%" EQU "%number%" echo - You are correct!
pause
if "%guess%" EQU "%number%" goto :start
if "%guess%" NEQ "%number%" goto :start
Re: Help with score system
when we use set /a score=%score% + 10
we update the value of score
but the display update of score is only when we reach echo %score%
in each label at the top there is a echo %score% so when we reach the labels the score will be updated
but if you mean you want to update it Immediately when the score get a new value you cant do that!
but i think that is possible using multi threading batch files!
about the to high and to low problem looks like the problem is with second label
your second problem might be solved now!
we update the value of score
but the display update of score is only when we reach echo %score%
in each label at the top there is a echo %score% so when we reach the labels the score will be updated
but if you mean you want to update it Immediately when the score get a new value you cant do that!
but i think that is possible using multi threading batch files!
about the to high and to low problem looks like the problem is with second label
Code: Select all
@echo off
title Guess the number!
color 04
set score= 0
:start
cls
set /a number=(%random% %%15)+1
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo %number%
echo.
echo - First attempt
echo.
set /P guess=- Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect!
if "%guess%" EQU "%number%" echo - You are correct!
if "%guess%" EQU "%number%" set /a score=%score%+10
if %guess% GTR %number% echo - Too high!
if %guess% LSS %number% echo - Too low!
pause
if "%guess%" NEQ "%number%" goto :second
if "%guess%" EQU "%number%" goto :start
:second
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo.
echo - Second attempt
echo.
set /P guess=Your guess:
echo.
if "%guess%" EQU "%number%" echo - You are correct! && set /a score=%score%+10
if %guess% GTR %number% echo - Too high! && echo - You are incorrect!
if %guess% LSS %number% echo - Too low! && echo - You are incorrect!
pause
if "%guess%" EQU "%number%" goto :start
if "%guess%" NEQ "%number%" goto :third
:third
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: %score%
echo.
echo - Final attempt
echo.
set /P guess=- Your guess:
echo.
if "%guess%" NEQ "%number%" echo - You are incorrect! You have no more attempts!
echo.
if "%guess%" NEQ "%number%" echo - The correct answer is %number%
if "%guess%" EQU "%number%" echo - You are correct! && set /a score=%score%+10
pause
if "%guess%" EQU "%number%" goto :start
if "%guess%" NEQ "%number%" goto :start
your second problem might be solved now!
Re: Help with score system
Here's a method that uses a loop.
It depends on the user entering a number because there is still no error checking,
but it seems to be ok here.
It depends on the user entering a number because there is still no error checking,
but it seems to be ok here.
Code: Select all
@echo off
title Guess the number!
color 04
set score=0
set ex=!
set tries=3
setlocal enabledelayedexpansion
:start
cls
set /a number=(%random% %% 15)+1
for /L %%a in (1,1,%tries%) do (
cls
echo -------------------------------------------------------------------------------
echo GUESS THE NUMBER
echo -------------------------------------------------------------------------------
echo Score: !score!
echo.
set /P "guess=%number% - attempt number %%a of %tries% - Your guess: "
echo.
if "!guess!" NEQ "%number%" echo - You are incorrect!ex!
if "!guess!" EQU "%number%" ( echo - You are correct!ex!
set /a score=score+10
ping -n 3 localhost >nul
goto :start
)
if !guess! GTR %number% echo - Too high!ex!
if !guess! LSS %number% echo - Too low!ex!
pause
)
if "%guess%" NEQ "%number%" ( echo - You are incorrect!ex! You have no more attempts!ex!
echo - The correct answer is %number%
)
ping -n 7 localhost >nul
pause