我正在尝试使用Batch制作基于文本的游戏,而这部分用于工作,但它突然没有。输入名称后,只要按Enter键,程序就会突然终止并显示错误:. was unexpected at this time
我很确定这不应该发生,我知道错误必须在以下代码中的某处:
`
:CFGNAME
cls & title N.A.M.E & color 0d
echo --------------------------------------
echo State your identity.
echo --------------------------------------
echo.
echo You need to specify things like your
echo name and gender.
echo.
echo.
echo.
echo Gender: %gender%
echo.
echo Enter a name. It may be up to sixteen
echo characters long, and can contain any
echo letter, and only letters. Most other
echo glyphs will crash the game.
echo.
echo.
echo -Enter a
set /p tmpName=- name:
echo %tmpName%> "data\temp\~playername.tmp"
for %%? in ("data\temp\~playername.tmp") do ( set /A nameLength=%%~z? - 2 )
del "data\temp\~playername.tmp"
set ucdName=%tmpName%
set ucdName=%ucdName:A= %
set ucdName=%ucdName:a= %
set ucdName=%ucdName:B= %
set ucdName=%ucdName:b= %
set ucdName=%ucdName:C= %
set ucdName=%ucdName:c= %
set ucdName=%ucdName:D= %
set ucdName=%ucdName:d= %
set ucdName=%ucdName:E= %
set ucdName=%ucdName:e= %
set ucdName=%ucdName:F= %
set ucdName=%ucdName:f= %
set ucdName=%ucdName:G= %
set ucdName=%ucdName:g= %
set ucdName=%ucdName:H= %
set ucdName=%ucdName:h= %
set ucdName=%ucdName:I= %
set ucdName=%ucdName:i= %
set ucdName=%ucdName:J= %
set ucdName=%ucdName:j= %
set ucdName=%ucdName:K= %
set ucdName=%ucdName:k= %
set ucdName=%ucdName:L= %
set ucdName=%ucdName:l= %
set ucdName=%ucdName:M= %
set ucdName=%ucdName:m= %
set ucdName=%ucdName:N= %
set ucdName=%ucdName:n= %
set ucdName=%ucdName:O= %
set ucdName=%ucdName:o= %
set ucdName=%ucdName:P= %
set ucdName=%ucdName:p= %
set ucdName=%ucdName:Q= %
set ucdName=%ucdName:q= %
set ucdName=%ucdName:R= %
set ucdName=%ucdName:r= %
set ucdName=%ucdName:S= %
set ucdName=%ucdName:s= %
set ucdName=%ucdName:T= %
set ucdName=%ucdName:t= %
set ucdName=%ucdName:U= %
set ucdName=%ucdName:u= %
set ucdName=%ucdName:V= %
set ucdName=%ucdName:v= %
set ucdName=%ucdName:W= %
set ucdName=%ucdName:w= %
set ucdName=%ucdName:X= %
set ucdName=%ucdName:x= %
set ucdName=%ucdName:Y= %
set ucdName=%ucdName:y= %
set ucdName=%ucdName:Z= %
set ucdName=%ucdName:z= %
set "ucdName=!ucdName: =!"
echo %ucdName%x> "data\temp\~checknamecontents.tmp"
for %%? in ("data\temp\~checknamecontents.tmp") do ( set /A invalidChars=%%~z? - 2 )
set /a invalidChars-=1
del "data\temp\~checknamecontents.tmp"
if %invalidChars% gtr 0 (
cls & title I.N.V.A.L.I.D & color 0c
echo.
echo Your name
echo must only contain letters!
echo.
echo The name you entered cannot be
echo used because if your name was
echo not fully alphabetical, pass-
echo words generated using that name
echo would be improperly generated.
echo It has %invalidChars%
echo invalid character(s).
echo.
echo Press any key to retry...
echo.
pause > nul
goto CFGNAME
)
:CHKNAMELENGTH
if %nameLength% gtr 16 (
cls & title I.N.V.A.L.I.D & color 0c
echo.
echo Your name must be up to 16
echo characters in length!
echo.
echo The name you entered cannot be
echo used because %nameLength% is
echo more than 16.
echo.
echo.
echo.
echo.
echo.
echo Press any key to retry...
echo.
pause > nul
goto CFGNAME
) else (
if %nameLength% lss 3 (
cls & title I.N.V.A.L.I.D & color 0c
echo.
echo Your name must be at least 3
echo characters in length!
echo.
echo The name you entered cannot be
echo used because %nameLength% is
echo less than 3.
echo.
echo.
echo.
echo.
echo.
echo Press any key to retry...
echo.
pause > nul
goto CFGNAME
) else (
set name=%tmpName%
goto CFGID
)
)
:CFGID
set IDEasterEgg=*
if /i "%tmpName%"=="Undyne" (
set IDEasterEgg=* Ngaaah!
)
if /i "%tmpName%"=="Frisk" (
set IDEasterEgg=* -_-
)
if /i "%tmpName%"=="Mario" (
set IDEasterEgg=* Lets-a-go!
)
if /i "%tmpName%"=="Waluigi" (
set IDEasterEgg=Waaa!
)
if /i "%tmpName%"=="Link" (
set IDEasterEgg=* Nice job, "princess."
)
if /i "%tmpName%"=="Navi" (
set IDEasterEgg=* Hey! Listen!
)
if /i "%tmpName%"=="Yoda" (
set IDEasterEgg=* Backwards I talk. Hm.
)
if /i "%tmpName%"=="Darth Vader" (
set IDEasterEgg=* No. I am your father.
)
if /i "%tmpName%"=="Mabbel" (
set IDEasterEgg=* GRAPPLING HOOK!!!
)
if /i "%tmpName%"=="Stanley" (
set IDEasterEgg=* Illegal pyrotechnics, anyone?
)
if /i "%tmpName%"=="Steve" (
set IDEasterEgg=* It's. A cow.
)
if /i "%tmpName%"=="Notch" (
set IDEasterEgg=* <3
)
if /i "%tmpName%"=="Caillou" (
set IDEasterEgg=* But Mommy!
)
if /i "%tmpName%"=="Rosie" (
set IDEasterEgg=* STUPID! STUPID! :D
)
if /i "%tmpName%"=="Testificate Man" (
set IDEasterEgg=* How inconsiderate!!!
)
if /i "%tmpName%"=="Dr Inconsiderate" (
set IDEasterEgg=* Slightly less than average!
)
if /i "%tmpName%"=="Shaggy" (
set IDEasterEgg=* Zoinks!
)
if /i "%tmpName%"=="Scooby-Doo" (
set IDEasterEgg=* Rello, rorld!!
)
if /i "%tmpName%"=="Santa Claus" (
set IDEasterEgg=* Ho ho ho!
)
if /i "%tmpName%"=="Easter Bunny" (
set IDEasterEgg=* You've found an Easter egg.
)
if /i "%tmpName%"=="Ed" (
set IDEasterEgg=* Head: Looks like flat pear.
)
if /i "%tmpName%"=="Edd" (
set IDEasterEgg=* Headwear: Very mysterious...
)
if /i "%tmpName%"=="Eddy" (
set IDEasterEgg=* Smile: Freakishly huge.
)
if /i "%tmpName%"=="Pacman" or "%tmpName%"=="Pac Man" (
set IDEasterEgg=* Wafers: A LOT
)
if /i "%tmpName%"=="Ms Pacman" or "%tmpName%"=="Ms Pac Man" (
set IDEasterEgg=* Children: Jr. Pac-Man
)
if /i "%tmpName%"=="Blinky" (
set IDEasterEgg=* Personality: Leader
)
if /i "%tmpName%"=="Clyde" (
set IDEasterEgg=* Personality: Teasing
)
if /i "%tmpName%"=="Inky" (
set IDEasterEgg=* Personality: Shy
)
if /i "%tmpName%"=="Pinky" (
set IDEasterEgg=* Personality: Energetic
)
if /i "%tmpName%"=="MatPat" (
set IDEasterEgg=* But that's just a theory.
)
:CFGID
cls & title Y.O.U S.U.R.E? & color 02
echo --------------------------------------
echo Is this ID okay with you?
echo ----------------------------------
echo This will be your character for the
echo rest of the game. Are you sure you
echo have everything exactly how you
echo want it? If not, you can go back
echo and edit your info all you like.
echo Anything but Y will be interpreted
echo as a no!
echo --------------------------------------
echo.
echo * Name: %name%
echo.
echo * Gender: %gender%
echo.
echo %IDEasterEgg%
echo.
echo __ __ __ __ __ __ ^|
echo _/ \__/ \__/ \__/ \__/ \__/ \__/
echo.
set /p confirmCharacter=(Y, N):
`
如果有人能够找出造成问题的原因,我真的很感激。
答案 0 :(得分:1)
行echo invalid character(s).
是问题所在。 )
关闭代码块,导致.
被解释为命令。用插入符号逃脱它:
echo invalid character(s^).