"CALL" 函数的用法 |批

Usage of "CALL" function | Batch

我是一个简单的人,所以如果能把它保持得尽可能简单,那就太好了
解决问题

@echo off
goto preparation

:damageCalculator
set /a damage=(((((2 * %level% / 5) + 2) * %attackStat% * %attackPower% / %opponentDefenceStat%) / 50) + 2)
set /a opponentHealth-=%damage%
echo %opponentHealth%
pause>nul

:preparation
set /a level=25
set /a attackStat=35
set /a attackPower=75
set /a opponentDefenceStat=46
set /a opponentHealth=350

:attack
call :damageCalculator
echo It did %damage% damage!!
pause>nul

问题是 "CALL" 充当 goto,我陷入了无限循环
我确定我没有正确设置它
请告诉我我做错的无数事情

您需要添加一个

goto :eof

从sub-routine和return退出到批处理文件的调用部分。

:damageCalculator
  set /a damage=(((((2 * %level% / 5) + 2) * %attackStat% * %attackPower% / %opponentDefenceStat%) / 50) + 2)
  set /a opponentHealth-=%damage%
  echo %opponentHealth%
  pause>nul

  goto :eof