( was unexpected at this time

Gigabyte / Awrdacpi
January 22, 2011 at 12:24:32
Specs: Windows XP, 2.21 GHz / 447 MB
While I was updating my game and just wanted to test this now, it opens, but when I close it and re-open it doesn't open and shows me this error. Sometimes that error appears when opening the .bat file, sometimes the .bat file works fine. So it happens at a random interval

This is the whole script:

:: Made by: Robert Lind @ January 20, 2011
:: Change Log:
:: v0.1 - Created Mathlogic
:: v0.11 - Fixed some bugs, added sounds, added more stuff
:: v0.12 - Shortened the code, fixed a few bugs, changed some few stuff
:: v0.13 - Fixed the division reward part, commented the second sndrec32 in script
:: v0.14 - Yay! Intro, Fixed the mult and div if being 0.
:: v0.15 - Bug fix, 3 second wait when getting a correct answer
::
:: There is still some few bugs in the game, this game is in pure beta version.
@echo off
cls
Title Mathlogic - A game where you take math - Level: 1 - Score: 0
Color 1f
set /a score=0
set /a intro=0
set /a level=1
set ver=v0.15
set mth=January
set dy=22
set yr=2011
::start /min musicplay


:setvars
cls
Title Mathlogic - A game where you take math - Level: %level% - Score: %score%
set /a res=%random%%%4
if %res% == 0 (
set /a num1=%random%%%1001
set /a num2=%random%%%1001
)
if %res% == 1 (
set /a num1=%random%%%1001
set /a num2=%random%%%1001
)
if %res% == 2 (
set /a num1=%random%%%101
set /a num2=%random%%%101
if %num1% == 0 (set num1=1)
if %num2% == 0 (set num2=1)
)
if %res% == 3 (
set /a num1=%random%%%1001
set /a num2=%random%%%11
if %num1% == 0 (set num1=1)
if %num2% == 0 (set num2=1)
)
if %res% == 0 (set /a resu=%num1%+%num2%)
if %res% == 1 (set /a resu=%num1%-%num2%)
if %res% == 2 (set /a resu=%num1%*%num2%)
if %res% == 3 (set /a resu=%num1%/%num2%)
if %res% == 0 (set /a bon=%num1%+%num2%)
if %res% == 1 (set /a bon=%num1%+%num2%)
if %res% == 2 (
set /a bone=%num1%*%num2%
set bon = %bone%/1.25
)
if %res% == 3 (set /a bon = %resu%*5)

if %intro% == 0 (
set intro=1
goto:intro
) else (
goto:game
)
pause>nul

:intro
cls
echo.
echo.
echo Yb dP 888888 88 dP""b8 dP"Yb 8b d8 888888 888888 dP"Yb
echo Yb db dP 88__ 88 dP `" dP Yb 88b d88 88__ 88 dP Yb
echo YbdPYbdP 88"" 88 .o Yb Yb dP 88YbdP88 88"" 88 Yb dP
echo YP YP 888888 88ood8 YboodP YbodP 88 YY 88 888888 88 YbodP
echo.
echo 8b d8 db 888888 88 88 88 dP"Yb dP""b8 88 dP""b8
echo 88b d88 dPYb 88 88 88 88 dP Yb dP `" 88 dP `"
echo 88YbdP88 dP__Yb 88 888888 88 .o Yb dP Yb "88 88 Yb
echo 88 YY 88 dP""""Yb 88 88 88 88ood8 YbodP YboodP 88 YboodP
echo %ver%
echo.
echo by: Robert Lind
echo.
echo.
echo Press the ENTER key to continue
pause>nul
goto:game

:game
cls
echo.
echo ------------------------------
echo [ ]
echo [ Mathlogic %ver% ]
echo [ by Robert Lind ]
echo [ ]
echo [ Created in: January 20, 2011 ]
echo [ Updated in: %mth% %dy%, %yr% ]
echo [ ]
echo ------------------------------
echo.
echo Score: %score% ----- Level: %level%
echo.
echo.
if %res% == 0 (echo How many is %num1% PLUS %num2%?)
if %res% == 1 (echo How many is %num1% MINUS %num2%?)
if %res% == 2 (echo How many is %num1% MULTIPLIED BY %num2%?)
if %res% == 3 (echo How many is %num1% DIVIDED BY %num2%?
echo.
echo.
echo REMEMBER TO ROUND THE NUMBERS DOWN! NOT UP!
echo.
echo Example: If the number is 4.39 or 4.93 doesnt matter which decimal it is
echo it equals 4!)
echo.
echo.
set /p ans=Type your answer here:
if %ans% == %resu% (
echo.
echo.
echo YOU WIN! IT WAS %resu%, SO YOU EARN %bon% POINTS!
echo.
echo.
::start /min sndrec32 /embedding /play /close "sounds\win.wav"
set /a score=%score%+%bon%
set /a level=%level%+1
goto:setvars
pause>nul
) else (
echo.
echo.
echo WRONG ANSWER! IT WAS %resu%.
echo.
echo.
::start /min sndrec32 /embedding /play /close "sounds\lose.wav"
goto:lose
pause>nul
)

:lose
cls
echo.
echo ------------------------------
echo [ ]
echo [ Mathlogic %ver% ]
echo [ by Robert Lind ]
echo [ ]
echo [ Created in: January 20, 2011 ]
echo [ Updated in: %mth% %dy%, %yr% ]
echo [ ]
echo ------------------------------
echo.
echo.
echo YOU LOST! TRY AGAIN!
echo.
echo.
echo Press the ENTER key to continue
set /a score=0
set /a level=1
Title Mathlogic - A game where you take math - Level: %level% - Score: %score%

pause>nul
goto:setvars

and no, it isn't all of those :: i've also tested it. But this is the line i've edited more:

if %res% == 2 (
set /a num1=%random%%%101
set /a num2=%random%%%101
if %num1% == 0 (set num1=1)
if %num2% == 0 (set num2=1)
)
if %res% == 3 (
set /a num1=%random%%%1001
set /a num2=%random%%%11
if %num1% == 0 (set num1=1)
if %num2% == 0 (set num2=1)
)

NOTE: However, when I made it thru v0.13 it never happened that. Now it's happening alot.

Thanks,
ptown2


See More: ( was unexpected at this time

Report •

#1
January 22, 2011 at 12:36:49
Hi ptown

if %res% == 3 (echo How many is %num1% DIVIDED BY %num2%?
echo.
echo.
echo REMEMBER TO ROUND THE NUMBERS DOWN! NOT UP!
echo.
echo Example: If the number is 4.39 or 4.93 doesnt matter which decimal it is
echo it equals 4!)

If the above is one if statment the ")" should be a the line below the "echo it equals 4!"
otherwise the loop is not complete.


Report •

#2
January 22, 2011 at 13:02:25
Nope, that part was still functioning well and I've found the problem. But thanks for the help anyways :)


It was one of the if statements being within another if statement and so on, so it made the bat somewhat unreadable at some points when opening.

However at this part:

echo.
set /p ans=Type your answer here:
if %resu% == %ans% (
echo.
echo.

If you put nothing at start, it closes automatically with that same error. Now if you put the answer then hold enter, it never closes and loops accordingly. How is it happening?


Report •

#3
January 22, 2011 at 18:30:24
:emptyinput
set /p ans=Type your answer here: 
if not defined ans goto emptyinput
if "%resu%"=="%ans:"=%" (


Report •
Related Solutions


Ask Question