我正在开发一款 RPG 风格的批处理游戏,但我一直goto was unexpected at this time.
在查看我的代码几个小时,但仍然不知道它为什么会这样做。
也是不一致的。在测试attack
动画时,当我击中slime
敌人时,我很少会在slime
没有关闭批处理文件的情况下杀死敌人。但是在其他时候我尝试这样做时,批处理文件就会自行终止。
这就是ht
, tm
,hm
等bm
事物的含义:
REM Sets box type.
set ht=Í
set hm=Í
set hb=Í
set vl=º
set vm=º
set vr=º
set tl=É
set tm=Ë
set tm2=Ë
set tr=»
set tr2=»
set ml2=Ì
set ml=Ì
set mm=Î
set mm2=Î
set mr2=¹
set mr=¹
set bl=È
set bm=Ê
set bm2=Ê
set br=¼
这是代码的“主体”。玩家将大部分时间花在哪里:
:battle
call :movement %movement%
set itemvar=0
set sx=1
set sx1=%icon%
set zz0=battle
set zz=battle2
set zz1=updo
set zz2=%zz%
set zz3=exit
set zz4=battlese
set zz5=batatk1
set max=4
set itemnum=0
set /a phpmaxh=%phpmax%/2
:battle2
set itemmenu=no
set itemmenu2=no
set battlemenu=no
set fight=no
set item=no
set menu=yes
if %pstatusch% == good (goto worncheck
) else (goto battle21)
:worncheck
if %php% leq %phpmaxh% (set pstatus=Worn Down
set pstatusch=worn)
:battle21
if %errorlevel% == 1 (set wcon=Û) else (set wcon= )
if %errorlevel% == 2 (set acon1=ß
set acon2=Ü) else (set acon1=
set acon2= )
if %errorlevel% == 3 (set scon=Û) else (set scon= )
if %errorlevel% == 4 (set dcon1=Ü
set dcon2=ß) else (set dcon1=
set dcon2= )
if %errorlevel% == 0 (set wcon=Ü
set scon=ß) else if %errorlevel% gtr 4 (set wcon=Ü
set scon=ß)
if %sx% == 1 (set detail= Swing your weapon at 'em. )
if %sx% == 2 (set detail= Cast a spell their way. )
if %sx% == 3 (set detail= Block and regain SPD. )
if %sx% == 4 (set detail= Use an item or two. )
if %php% lss 10 (set phpsp= ) else (set phpsp=)
if %pmp% lss 10 (set pmpsp= ) else (set pmpsp=)
if %phpmax% lss 10 (set phpmaxsp= ) else (set phpmaxsp=)
if %pmpmax% lss 10 (set pmpmaxsp= ) else (set pmpmaxsp=)
if %patk% lss 10 (set patksp= ) else (set patksp=)
if %pdef% lss 10 (set pdefsp= ) else (set pdefsp=)
if %pint% lss 10 (set pintsp= ) else (set pintsp=)
if %pspd% lss 10 (set pspdsp= ) else (set pspdsp=)
if %pdefmax% lss 10 (set pdefmaxsp= ) else (set pdefmaxsp=)
if %pintmax% lss 10 (set pintmaxsp= ) else (set pintmaxsp=)
if %pspdmax% lss 10 (set pspdmaxsp= ) else (set pspdmaxsp=)
if %pshdrb% lss 10 (set shdrbsp= ) else (set shdrbsp=)
if %pardrb% lss 10 (set ardrbsp= ) else (set ardrbsp=)
if %pbtdrb% lss 10 (set btdrbsp= ) else (set btdrbsp=)
if %pexp% lss 10 (set pexpsp= ) else (set pexpsp=)
if %plvl% lss 10 (set plvlsp= ) else (set plvlsp=)
:battle3
if %menu% == yes (mode con: cols=65 lines=19
) else if %fight% == yes (mode con: cols=65 lines=17
) else (mode con: cols=65 lines=24)
if %menu% == yes (call :normal_menu menu1,menu2,menu3,menu4,menu5,menu6
) else if %itemmenu% == yes (call :normal_menu2 menu1,menu2,menu3,menu4,menu5,menu6
) else if %battlemenu% == yes (call :normal_menu3 menu1,menu2,menu3,menu4,menu5,menu6)
cls
echo.
echo.
echo %tl%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%tr% %enemy1% %menu1%
echo %vl% %ename%%enamesp% %vr% %enemy2% %menu2%
echo %ml%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%mr% %enemy3% %menu3%
echo %vl% HP %ehpbar% %vr% %enemy4% %menu4%
echo %bl%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%br% %enemy5% %menu5%
echo %enemy6% %menu6%
echo.
if %itemmenu2% == yes (goto %zz5%
) else if %fight% == yes (goto %zz5%)
echo %tl%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%tm%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%tr% %tl%%ht%%ht%%ht%%ht%%tm%%ht%%ht%%ht%%ht%%tr%
echo %vl% Status %vm% %pstatus% %vr% %vl%Curr%vm%Max %vr%
echo %ml%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%mm%%hm%%hm%%hm%%hm%%tm2%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%bm2%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%tm2%%hm%%hm%%hm%%hm%%hm%%mm%%hm%%hm%%hm%%hm%%mm%%hm%%hm%%hm%%hm%%mr%
echo %vl% Shield %vm% %shdrbsp%%pshdrb% %vm% %detail% %vm% HP %vm% %phpsp%%php% %vm% %phpmaxsp%%phpmax% %vr%
echo %vl% Armor %vm% %ardrbsp%%pardrb% %ml2%%hm%%hm%%hm%%hm%%hm%%tm2%%hm%%hm%%hm%%hm%%tm2%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%tm2%%hm%%hm%%hm%%hm%%hm%%tm2%%hm%%hm%%hm%%hm%%mr2% MP %vm% %pmpsp%%pmp% %vm% %pmpmaxsp%%pmpmax% %vr%
echo %vl% Boots %vm% %btdrbsp%%pbtdrb% %vm% LVL %vm% %plvlsp%%plvl% %vm% %acon2% %wcon% %dcon1% %vm% ATK %vm% %patksp%%patk% %vm% DEF %vm% %pdefsp%%pdef% %vm% %pdefmaxsp%%pdefmax% %vr%
echo %vl% %vm% %vm% EXP %vm% %pexpsp%%pexp% %vm% %acon1% %scon% %dcon2% %vm% INT %vm% %pintsp%%pint% %vm% SPD %vm% %pspdsp%%pspd% %vm% %pspdmaxsp%%pspdmax% %vr%
echo %bl%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%bm%%hb%%hb%%hb%%hb%%bm%%hb%%hb%%hb%%hb%%hb%%bm%%hb%%hb%%hb%%hb%%bm%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%bm%%hb%%hb%%hb%%hb%%hb%%bm%%hb%%hb%%hb%%hb%%bm%%hb%%hb%%hb%%hb%%hb%%bm%%hb%%hb%%hb%%hb%%bm%%hb%%hb%%hb%%hb%%br%
goto wasdqe /nul
这就是问题出现的地方。陈述的部分else if %sx% == 4 (set menu...)
工作正常,只是if %sx% == 1 (goto %zz5%)
似乎有问题。我想指出,切换%zz5%
到batatk1
并不能解决问题。
:battlese
if %sx% == 1 (goto %zz5%
) else if %sx% == 4 (set menu=no
set item=yes
goto itemselect)
另外,这里是batatk1的代码:
:batatk1
set extradamageatk=+0
set extradamageint=+0
set weaponatk=yes
if %wpequip1% == yes (set x6=%wpequip1%
set x7=%inven1sp%
set x8=%inven1%
set x9=%inname1%
set x10=%wint1%
set x11=%watk1%
set x12=1
set x13=%wdrb1%
set x14=%wdrb1%
) else if %wpequip2% == yes (set x6=%wpequip2%
set x7=%inven2sp%
set x8=%inven2%
set x9=%inname2%
set x10=%wint2%
set x11=%watk2%
set x12=2
set x13=%wdrb2%
set x14=wdrb2
) else if %wpequip3% == yes (set x6=%wpequip3%
set x7=%inven3sp%
set x8=%inven3%
set x9=%inname3%
set x10=%wint3%
set x11=%watk3%
set x12=3
set x13=%wdrb3%
set x14=wdrb3
) else if %wpequip4% == yes (set x6=%wpequip4%
set x7=%inven4sp%
set x8=%inven4%
set x9=%inname4%
set x10=%wint4%
set x11=%watk4%
set x12=4
set x13=%wdrb4%
set x14=wdrb4
) else if %wpequip5% == yes (set x6=%wpequip5%
set x7=%inven5sp%
set x8=%inven5%
set x9=%inname5%
set x10=%wint5%
set x11=%watk5%
set x12=5
set x13=%wdrb5%
set x14=wdrb5
) else if %wpequip6% == yes (set x6=%wpequip6%
set x7=%inven6sp%
set x8=%inven6%
set x9=%inname6%
set x10=%wint6%
set x11=%watk6%
set x12=6
set x13=%wdrb6%
set x14=wdrb6
) else if %wpequip7% == yes (set x6=%wpequip7%
set x7=%inven7sp%
set x8=%inven7%
set x9=%inname7%
set x10=%wint7%
set x11=%watk7%
set x12=7
set x13=%wdrb7%
set x14=wdrb7
) else if %wpequip8% == yes (set x6=%wpequip8%
set x7=%inven8sp%
set x8=%inven8%
set x9=%inname8%
set x10=%wint8%
set x11=%watk8%
set x12=8
set x13=%wdrb8%
set x14=wdrb8
) else if %wpequip9% == yes (set x6=%wpequip9%
set x7=%inven9sp%
set x8=%inven9%
set x9=%inname9%
set x10=%wint9%
set x11=%watk9%
set x12=9
set x13=%wdrb9%
set x14=wdrb9
) else if %wpequip10% == yes (set x6=%wpequip10%
set x7=%inven10sp%
set x8=%inven10%
set x9=%inname10%
set x10=%wint10%
set x11=%watk10%
set x12=10
set x13=%wdrb10%
set x14=wdrb10
) else if %wpequip11% == yes (set x6=%wpequip11%
set x7=%inven11sp%
set x8=%inven11%
set x9=%inname11%
set x10=%wint11%
set x11=%watk11%
set x12=11
set x13=%wdrb11%
set x14=wdrb11
) else if %wpequip12% == yes (set x6=%wpequip12%
set x7=%inven12sp%
set x8=%inven12%
set x9=%inname12%
set x10=%wint12%
set x11=%watk12%
set x12=12
set x13=%wdrb12%
set x14=wdrb12
) else if %wpequip13% == yes (set x6=%wpequip13%
set x7=%inven13sp%
set x8=%inven13%
set x9=%inname13%
set x10=%wint13%
set x11=%watk13%
set x12=13
set x13=%wdrb13%
set x14=wdrb13
) else if %wpequip14% == yes (set x6=%wpequip14%
set x7=%inven14sp%
set x8=%inven14%
set x9=%inname14%
set x10=%wint14%
set x11=%watk14%
set x12=14
set x13=%wdrb14%
set x14=wdrb14
) else if %wpequip15% == yes (set x6=%wpequip15%
set x7=%inven15sp%
set x8=%inven15%
set x9=%inname15%
set x10=%wint15%
set x11=%watk15%
set x12=15
set x13=%wdrb15%
set x14=wdrb15
) else (set weaponatk=no)
set fn=0
set crit=1
:batatk2
set /a fn=%fn%+1
set /a rd%fn%=%random%/5500
if %fn% neq 2 goto batatk2
set fn=0
if %eability% == jelly (set extradamageatk=/2)
set /a crit=%rd1%-%rd2%
if %crit% lss 0 (set crit=+0) else (set crit=+%crit%)
if %rd1% == %rd2% goto rdcheck
if %pability% == weakspot (goto pweakspot)
if %equipatk% == physical (goto batatkph
) else if %equipatk% == mystic (goto batatkmy
) else if %equipatk% == both (goto batatkboth)
goto error
:rdcheck
if %rd1% == 0 (set /a miss=%miss%+1
) else if %rd1% == 5 (set crit=*2)
if %miss% == 2 goto pmiss
if %pability% == weakspot (goto pweakspot)
if %equipatk% == physical (goto batatkph
) else if %equipatk% == mystic (goto batatkmy
) else if %equipatk% == both (goto batatkboth)
goto error
:pweakspot
if %eability% == jelly (goto batatkmy
) else if %emp% gtr %ehp% (goto batatkph
) else if %ehp% gtr %emp% (goto batatkmy
)
goto error
:batatk3
set /a fn=%fn%+1
set /a rd%fn%=%random%/5500
if %fn% neq 2 goto batatk3
if %edamage% gtr 9 (set edamagesp=) else (set edamagesp= )
set fn=0
if %crit% == *2 (set rd1=0
set rd2=0)
if %rd1% == %rd2% (goto weapondamage)
:batatk4
set /a fn=%fn%+1
if %fn% == 2 (set enemy1= ÜßÜ Ü
set enemy2= ÜÛ ÛÜ ßÜß
set enemy3= ÜÛ ÛÜ
set enemy4=ÞÛ ÛÜ ÜÛ ÛÝ
set enemy5=ÞÛ ÜÜÜ ÛÝ
set enemy6= ßßÜÜÜÜÜÜÜßß )
if %fn% == 3 (set enemy1= ÜßÜ Ü
set enemy2= ÜÛ ÛÜ ßÜß
set enemy3= ÜÛ ÛÜ
set enemy4= ÞÛ ÛÜ ÜÛ ÛÝ
set enemy5= ÞÛ ÜÜÜ ÛÝ
set enemy6= ßßÜÜÜÜÜÜÜßß )
if %fn% == 4 (set enemy1= ÜßÜ Ü
set enemy2= ÜÛ ÛÜ ßÜß
set enemy3= ÜÛ ÛÜ
set enemy4=ÞÛ ÛÜ ÜÛ ÛÝ
set enemy5=ÞÛ ÜÜÜ ÛÝ
set enemy6= ßßÜÜÜÜÜÜÜßß )
if %fn% == 5 (set enemy1= ÜßÜ
set enemy2= ÜÛ ÛÜ
set enemy3= ÜÛ ÛÜ
set enemy4=ÞÛ Ûß ßÛ ÛÝ
set enemy5=ÞÛ ÜÜÜ ÛÝ
set enemy6= ßßÜÜÜÜÜÜÜßß )
cls
echo.
echo.
echo %tl%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%tr% %enemy1% %menu1%
echo %vl% %ename%%enamesp% %vr% %enemy2% %menu2%
echo %ml%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%hm%%mr% %enemy3% %menu3%
echo %vl% HP %ehpbar% %vr% %enemy4% %menu4%
echo %bl%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%br% %enemy5% %menu5%
echo %enemy6% %menu6%
echo %tl%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%ht%%tr%
if %weaponatk% == yes (echo %vl%%enamesp% You swung your %x8% at the %ename%! %x7%%vr%
) else if %weaponatk% == no (echo %vl% You punched the %ename%! %enamesp% %vr%)
echo %vl% The enemy took %edamage% damage! %edamagesp% %vr%
echo %bl%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%hb%%br%
if %fn% == 2 goto batatk6
:batatk5
if %fn% gtr 5 (set /a fn=%fn%+1)
if %fn% lss 6 (
timeout /t 0 >nul
) else (
timeout /t -1 >nul)
if %fn% lss 6 (goto batatk4)
if %ehp% leq 0 (set ehp=0
goto battle_win)
goto %zz0%
:batatk6
if %ehp% leq 0 (set ehpbar=°°°°°°°°°°
) else if %ehp% == 1 (set ehpbar=²°°°°°°°°°
) else if %ehp% == 2 (set ehpbar=Û°°°°°°°°°
) else if %ehp% == 3 (set ehpbar=Û²°°°°°°°°
) else if %ehp% == 4 (set ehpbar=ÛÛ°°°°°°°°
) else if %ehp% == 5 (set ehpbar=ÛÛ²°°°°°°°
) else if %ehp% == 6 (set ehpbar=ÛÛÛ°°°°°°°
) else if %ehp% == 7 (set ehpbar=ÛÛÛ²°°°°°°
) else if %ehp% == 8 (set ehpbar=ÛÛÛÛ°°°°°°
) else if %ehp% == 9 (set ehpbar=ÛÛÛÛ²°°°°°
) else if %ehp% == 10 (set ehpbar=ÛÛÛÛÛ°°°°°
) else if %ehp% == 11 (set ehpbar=ÛÛÛÛÛ²°°°°
) else if %ehp% == 12 (set ehpbar=ÛÛÛÛÛÛ°°°°
) else if %ehp% == 13 (set ehpbar=ÛÛÛÛÛÛ²°°°
) else if %ehp% == 14 (set ehpbar=ÛÛÛÛÛÛÛ°°°
) else if %ehp% == 15 (set ehpbar=ÛÛÛÛÛÛÛ²°°
) else if %ehp% == 16 (set ehpbar=ÛÛÛÛÛÛÛÛ°°
) else if %ehp% == 17 (set ehpbar=ÛÛÛÛÛÛÛÛ²°
) else if %ehp% == 18 (set ehpbar=ÛÛÛÛÛÛÛÛÛ°
) else if %ehp% == 19 (set ehpbar=ÛÛÛÛÛÛÛÛÛ²
) else if %ehp% == 20 (set ehpbar=ÛÛÛÛÛÛÛÛÛÛ)
goto batatk4
:weapondamage
if %weapondamage% == no goto batatk4
if %rd1% == 0 (set /a %x14%=%x13%-2) else (set /a %x14%=%x13%-1)
if %rd1% == 0 (set /a x13=%x13%-2) else (set /a x13=%x13%-1)
if %x13% leq 0 (set item%x12%=none
set inven%x12%=Scraps
set inname%x12%=none
set wpequip%x12%=no
set indesc%x12%=%x9%
set x9=none
set equipatk=physical)
if %x9% == woodsword (set indesc%x12%=A toy children play with. ATK:3 DRB:%x13%
) else if %x9% == woodstaff (set indesc%x12%=A type of staff used on hiking trips. INT:3 DRB:%x13%
) else if %x9% == wooddagger (set indesc%x12%=Artistic carving of a beautiful dagger. INT/ATK:2 DRB:%x13%
) else if %x9% == none (set indesc%x12%=Scraps left behind from shattered equipment. )
if %x13% leq 0 (set /a patk=%patk%-%x11%)
if %x13% leq 0 (set /a pint=%pint%-%x10%)
goto batatk4
:batatkph
set /a edamage=((%patk%%crit%)%extradamageatk%)-%edef%
if %edamage% leq 0 (set edamage=1)
set /a ehp=%ehp%-%edamage%
goto batatk3
:batatkmy
set /a edamage=((%pint%%crit%)%extradamageint%)-%edef%
if %edamage% leq 0 (set edamage=1)
set /a ehp=%ehp%-%edamage%
goto batatk3
导致我的游戏无法正常运行的唯一问题是if %sx% == 1 (goto %zz5%)
,我不知道该怎么办。我尝试将我的代码复制并粘贴到一个新程序上。我试过把它保存在记事本上,我试过记事本++,我什至把它从我做的循环开关的数量切换到现在正在做的事情,但它仍然无法正常工作。我什至尝试稍微清理一下我的代码,但这并没有解决任何问题。这个问题直到我添加了Smoosh
(史莱姆敌人的名字)动画才开始。在此之前,完全没有问题。Slime 动画可以在中找到:batatk4
,:batatk6
感谢您花时间阅读并查看大量代码。如果有人能弄清楚我做错了什么,我将不胜感激。