gpt4 book ai didi

windows - 我只为一组/一个不断收到大量错误

转载 作者:可可西里 更新时间:2023-11-01 10:35:50 27 4
gpt4 key购买 nike

Alright so I am making a pretty simple game in batch and I decided I wanted to add some abilities to enemies. I tried to make a code that would let them use abilities but it crashes after a set /a statement with nothing wrong with it. My code that is relevant is separated into 4 main parts. I'm going to put the code in order of where they are in my file. These are not the only things in it. All my characters stats like strength, stamina, agility, and intellect are working perfectly fine.


敌人的初始化

这是战斗开始时加载的内容,用于提供敌人统计信息等。

: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 "/" was unexpected at this time.

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

here is the link to it .如果您不太想检查它,它会加载您的 bat 文件并使用所有代码和 goto 并检查错误。但是它确实使用暂停来强制它停止。我通过将其添加到我的战斗屏幕来解决此问题。

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 部分周围加上引号来修复它,除了像

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

但这并没有真正解决问题。它所做的只是改变

A "/" was unexpected at this time.

The syntax of the command is incorrect.

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


结论

这就是我真正需要解决的问题。
一些帮助和/或建议会非常好!几天来我一直在努力解决这个问题。 :/
如果我所说的内容中有任何您不理解的部分,或者您需要更多信息,请询问。


好吧,我确实最终将我的代码中的括号和引用中的/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

根据之前的评论,我已经检查了好几次,但似乎仍然遇到同样的错误。

The syntax of the command is incorrect.
set /a abilchecker=%abilchecker% - 1

最佳答案

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

此处最后一行的右括号关闭了 if %enemyenergy% ... ( block 。

您需要使用 ^ 转义右括号因此:

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

自然地,在您向我们展示的堆积如山的代码中有很多这样的情况。

接下来,尝试为任何numeric 赋值set/a,并在numeric 赋值中去掉引号。使用 set "var=string" 分配 strings,因为引号确保尾随空格不包含在分配的值中。

然后尝试 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 个区 block - 并且一个都没有关闭。除非你删掉了一堆右括号,否则就是这样。

当你在该地区时,你有

set enemyability1truedamage=0

set/a...

作为数字赋值更好

请学会缩进。它使 block 语句更具可读性。

关于windows - 我只为一组/一个不断收到大量错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27317307/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com