我只会在一组/每组中遇到大量错误

时间:2014-12-05 13:45:40

标签: windows batch-file

  

好吧所以我正在批量制作一个非常简单的游戏,我决定要为敌人增加一些能力。我尝试制作一个让他们使用能力的代码,但它在一个/它没有任何错误的set / a语句后崩溃。我的相关代码分为4个主要部分。   我将把代码按照它们在我的文件中的顺序排列。这些并不是唯一的东西。我的所有角色统计数据如力量,耐力,敏捷和智力都非常好。


敌人的初始化

这是在战斗开始时加载敌人的统计数据等等。

:bearstart1
set enemytype=beast
set curenemy=Bear
set /a allstat= %strength% + %stamina% + %agility% + %intellect%
set /a randamage= %weapondamage% / (%level% * 2)
set enevasion=1
set /a hitacc= %accuracy% * 10
set /a hitran=%RANDOM% * (1000 - 1 + 1) / 32768 + 1
set enemyaccuracy=1
set /a eneacc= %enemyaccuracy% * 10
set /a enemylevel= %RANDOM% * (2 - 1 + 1) / 32768 + 1
set enemyhealth=75 + (5 * %enemylevel%)
set enemymaxhealth=75 + (5 * %enemylevel%)
set enemyenrgy=30 + (%enemylevel% * 5)
set /a enemyenergy=%enemyenrgy%
set enemymaxenergy=30 + (%enemylevel% * 5)
set enemyenergyregen=2
set enemydefense=17 + %enemylevel%
set /a enemyabilities=1
set enemycurabilityname=Claw
set enemycurabilityID=001
set enemycurabilityslot=1
set enemycurabilitychance=30
set statfixloc=bearstart2
goto :statfixesenemyability
:bearstart2
set enevasion=1
set /a enemydamage=18 + %enemylevel%
set /a ranxpgain=(%RANDOM% * ((10 * %level%) - 1 + 1) / 32768 + 1)
set /a ranxpgain=(%RANDOM% * ((15 * %level%) - 1 + 1) / 32768 + 1)
set /a atkaccuracy= (550 + %hitacc%) - (%enevasion% * 10)
set /a eneaccuracy= (450 + %eneacc%) - (%evasion% * 10)
set enemyattack= %enemydamage% - (%defense% / 2)
set /a realdamage= %damage% - (%enemydefense% / 2)
set /a randamagemax= %realdamage% + randamage
set /a randamagemin= %realdamage% - randamage
set /a randomdamage= %RANDOM% * (%randamagemax% - %randamagemin% + 1) / 32768 + %randamagemin%
set /a enemyrandamage= %enemydamage% / (%enemylevel% * 3)
set /a enemyrealdamage= %enemydamage% - (%defense% / 2) + (%enemylevel% - 1 * 5)
set /a enemyrandamagemax= %enemyrealdamage% + %enemyrandamage%
set /a enemyrandamagemin= %enemyrealdamage% - %enemyrandamage%
set /a enemyrandomdamage= %RANDOM% * (%enemyrandamagemax% - %enemyrandamagemin% + 1) / 32768 + %enemyrandamagemin%

战斗屏幕

这是一个菜单,玩家可以选择在战斗中做什么选项,主要是参考这些代码部分所在的顺序。这实际上是上面初始化后的一行

:fightscreen
set /a health=%health%
set /a enemyhealth=%health%
IF %health% LEQ 0 goto :dead
IF %enemyhealth% LEQ 0 goto :fightend
cls
Echo ######################################
Echo # Enemy:%curenemy%
Echo # Enemy Health: %enemyhealth%/%enemymaxhealth%
Echo # Enemy Energy: %enemyenergy%/%enemymaxenergy%
Echo # Enemy Defense: %enemydefense%
Echo # Enemy Attack: %enemyattack%
Echo ######################################
Echo # %name%
Echo # Level:%level%
Echo # Health:%health%/%maxhealth%
Echo # Damage:%randamagemin%-%randamagemax%
Echo # Defense:%defense%
Echo # XP:%xp%/%maxxp%
Echo # Gold:%gold%
Echo ######################################
Echo #                                    #
Echo #         Decisions              #
Echo ######################################
Echo #                                    #
Echo # 1).Attack                          #
Echo # 2).Use Potion                      #
Echo # 3).Flee                            #
Echo #                                    #
Echo ######################################
IF "%1" == "-debug" (
set fightchoice= 1
goto fightscreenoveride
)
set /p fightchoice= Choose your decision. 
:fightscreenoveride
IF %fightchoice% == 1 goto fightattack
IF %fightchoice% == 2 goto fightpotion
IF %fightchoice% == 3 goto flee
goto fighterror1

" 脚本"战斗

这是持续崩溃的主要部分。

:fightdefend
IF "%enemyhealth%" LEQ "0" goto :fightend
cls
set /a abilchecker=%enemyabilities%
:fightenemyability
set /a abilchecker= %abilchecker% - 1
IF %abilchecker% GEQ 0 (
IF "%enemyability1type%"=="1" (
IF "%enemyability1costbool%"=="1" (
IF %enemyenergy% GEQ %enemyability1cost% (
set /a "enemyenergy="%enemyenergy% - %enemyability1cost%"
set /a "enemyability1hitchnc= %RANDOM% * (100 - 1 + 1) / 32768 + 1"
set /a enemyability1hitchanc=%enemyability1hitchnc%
set /a enemyability1hitchance=%enemyability1hitchanc%
IF "%enemyability1choosechance% LEQ "%enemyabilty1hitchance%" 
set /a "enemyability1hitchnc= %RANDOM% * (100 - 1 + 1) / 32768 + 1"
set /a enemyabiltiy1hchance=%enemyability1hitchnc%
IF "%enemyability1chance%" LEQ "%enemyability1hchance%" (
set /a "enemyability1damge= %RANDOM% * (%enemyability1dmgmax% - %enemyability1dmgmin% + 1) / 32768 + %enemyability1dmgmin%"
set /a enemyability1damage=%enemyabiltiy1damge%
set /a "enemyability1truedamge= %enemyability1damge% - (%defense% / 2)"
set /a enemyability1truedamage=%enemyability1truedamge%
IF "%enemyability1truedamage%" LEQ "0" (
set enemyability1truedamage=0
Echo %curenemy% used %enemyability1name% and hit you for %enemyability1truedamage%!
pause >nul
goto :fightscreen
)
set /a "health=%health% - %enemyability1truedamage%"
Echo %curenemy% used %enemyability1name% and hit you for %enemyability1truedamage%!
pause >nuls
goto :fightscreen
) ELSE (
Echo %curenemy% used %enemyability1name%... But %curenemy% missed!
pause >nul
goto fightscreen
)
 )
  goto fightenemyability
  )
 goto :fightenemyability
  ) ELSE (
set /a "enemyability1hitchnc= %RANDOM% * (100 - 1 + 1) / 32768 + 1"
set /a enemyability1hitchance=%enemyability1hitchnc%
IF "%enemyability1choosechance%" LEQ "%enemyabilty1hitchance%" (
set /a "enemyability1hitchnc= %RANDOM% * (100 - 1 + 1) / 32768 + 1"
set /a enemyabiltiy1hchance=%enemyability1hitchnc%
IF "%enemyability1chance%" LEQ "%enemyability1hchance%" (
set /a "enemyability1dmg= %RANDOM% * (%enemyability1dmgmax% - %enemyability1dmgmin% + 1) / 32768 + %enemyability1dmgmin%"
set /a enemyability1damage=%enemyability1dmg%
set /a "enemyability1truedmg= %enemyability1damage% - (%defense% / 2)"
set /a enemyability1truedamage=%enemyability1truedmg%
IF "%enemyability1truedamage%" LEQ "0" (
set enemyability1truedamage=0
Echo %curenemy% used %enemyability1name% and hit you for %enemyability1truedamage%!
pause >nul
goto :fightscreen
)
set /a "health=%health% - %enemyability1truedamage%"
Echo %curenemy% used %enemyability1name% and hit you for %enemyability1truedamage%!
pause >nul
goto :fightscreen
) ELSE (
Echo %curenemy% used %enemyability1name%... But %curenemy% missed!
pause >nul
goto fightscreen
  )
   )
    )
     )
      )
:fightdefendattack
set /a "enemyrandomdamage= %RANDOM% * (%enemyrandamagemax% - %enemyrandamagemin% + 1) / 32768 + %enemyrandamagemin% "
set /a "hitran=%RANDOM% * (1000 - 1 + 1) / 32768 + 1"
if %hitran% LSS %eneaccuracy% goto enemymiss
goto enemyhit

设置敌人的能力

这是设定敌人能力的地方。这会将你从:bearstart1发送到此,然后发送到:bearstart2

:statfixesenemyability
goto :ability%enemycurabilityID%
:ability001
::Claw
set enemyability%enemycurabilityslot%name=%enemycurabilityname%
set /a enemyability%enemycurabilityslot%type=1
set /a enemyability%enemycurabilityslot%costbool=1
set enemyability%enemycurabilityslot%choosechance=%enemycurabilitychance%
set enemyability%enemycurabilityslot%chance=60
set enemyability%enemycurabilityslot%cost=10
set enemyability%enemycurabilityslot%dmgmin=10
set enemyability%enemycurabilityslot%dmgmax=50
set /a enemyability%enemycurabilityslot%effectbool=0
set /a enemyability%enemycurabilityslot%effect=None
set enemyability%enemycurabilityslot%efsfectchance=0
set enemyability%enemycurabilityslot%effectmin=0
set enemyability%enemycurabilityslot%effectmax=0
set enemyability%enemycurabilityslot%effectlastmin=0
set enemyability%enemycurabilityslot%effectlastmax=0
set enemyability%enemycurabilityslot%activated=1
goto :%statfixloc%

所以当它第一次崩溃时就会出现这个错误:

  

A" /"这时出人意料。

所以我使用了一个从搜索stackoverflow得到的bat调试器。

here is the link to it。如果您不想检查它几乎加载您的bat文件并使用所有代码和gotos并检查错误。然而,它确实使用暂停,迫使它停止。我把它添加到我的fightscreen中来解决这个问题。

IF "%1" == "-debug" (
set fightchoice= 1
goto fightscreenoveride
)

并使用

加载它
start logfile.bat tatatat0-batchz-rpg.bat -debug

我发现使用了

set /a abilchecker= 1 - 1 

代码中的

set /a abilchecker= %abilchecker% - 1

注意:我确实将abilchecker设置为%enemiesabilities%前几行 这段代码一直在崩溃,或者至少是崩溃的第一件事。所以我尝试通过在除了

之外的所有集合/部件周围加上引号来修复它
set /a "enemyability1hitchnc= %RANDOM% * (100 - 1 + 1) / 32768 + 1"

虽然没有真正解决这个问题。所有这一切都是改变

  

A" /"这时出人意料。

  

该命令的语法不正确。

这个错误没有多大意义,因为set / a abilchecker的语法很好。这是我被困一段时间的地方,我不知道如何解决它。


结论

这就是我真正对待我的问题。
一些帮助和/或建议会非常好!我已经试图解决这个问题好几天了。 :/
如果我说的任何部分你都不明白,或者你需要更多的信息,请问。


好吧,我最后更改了我的括号,并在我的代码中的set / a中引用:

(Just a 'portion' of it)

set /a abilchecker=%abilchecker% - 1
IF %abilchecker% GEQ 0 (
IF "%enemyability1type%"=="1" (
IF "%enemyability1costbool%"=="1" (
IF %enemyenergy% GEQ %enemyability1cost% (
set /a enemyenergy=%enemyenergy% - %enemyability1cost%
set /a enemyability1hitchnc=%RANDOM% * (100 - 1 + 1^) / 32768 + 1
set /a enemyability1hitchanc=%enemyability1hitchnc%
set /a enemyability1hitchance=%enemyability1hitchanc%
IF %enemyability1choosechance% LEQ %enemyabilty1hitchance%
set /a enemyability1hitchnc=%RANDOM% * (100 - 1 + 1^) / 32768 + 1
set /a enemyabiltiy1hchance=%enemyability1hitchnc%
IF %enemyability1chance% LEQ %enemyability1hchance% (
set /a enemyability1damge=%RANDOM% * (%enemyability1dmgmax% - %enemyability1dmgmin% + 1^) / 32768 + %enemyability1dmgmin%
set /a enemyability1damage=%enemyabiltiy1damge%
set /a enemyability1truedamge=%enemyability1damge% - (%defense% / 2^)
set /a enemyability1truedamage=%enemyability1truedamge%
IF %enemyability1truedamage% LEQ 0 (
set enemyability1truedamage=0
Echo %curenemy% used %enemyability1name% and hit you for %enemyability1truedamage%!
pause >nul
goto :fightscreen

我在之前的评论之后已多次查看过,但似乎仍然遇到同样的错误。

  

命令的语法不正确       set / a abilchecker =%abilchecker% - 1

1 个答案:

答案 0 :(得分:1)

IF "%enemyability1costbool%"=="1" (
IF %enemyenergy% GEQ %enemyability1cost% (
set /a "enemyenergy="%enemyenergy% - %enemyability1cost%"
set /a "enemyability1hitchnc= %RANDOM% * (100 - 1 + 1) / 32768 + 1"

最后一行的近括号将关闭if %enemyenergy% ... (块。

您需要使用^转义该括号:

set /a "enemyability1hitchnc= %RANDOM% * (100 - 1 + 1^) / 32768 + 1"

当然,在你向我们展示的代码之中,有很多这样的情况。

接下来,针对任何数字分配尝试set /a,并在数字分配中抛出引用。使用set "var=string"指定字符串,因为引号可确保所分配的值中不包含尾随空格。

并尝试set /a var=(%random% %% rangemax) + 1设置值1..rangemax

你甚至可以写一个子程序:

:randrange
set /a %1=1+(%random% %% %2)
goto :eof

然后,只要你想要一个随机数1..rangemax,只需使用

call :randrange nameofvariabletoset rangemax

这将保存所有重复输入 - 但我从你的变量命名方案中看到你喜欢打字。嗯 - 考虑所有类型,我想......


最新回复:

该行

    IF %enemyability1choosechance% LEQ %enemyabilty1hitchance%

语法错误(缺少(

意识到那时你已经打开了4个街区,那是第五个?你继续打开7个街区 - 并且没有关闭。除非你对一堆近括号进行审查,否则就是这样。

当你在该地区时,你已经

set enemyability1truedamage=0

使用set /a...

作为数字作业最好

请学习缩进。它使块语句更具可读性。