Advertisement
T3RRYT3RR0R

Batch Math Macro

Apr 4th, 2020
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.15 KB | None | 0 0
  1. @Echo Off
  2.     setlocal DisableDelayedExpansion
  3.     (set LF=^
  4.  
  5.  
  6.     %= Newline =%)
  7.     Set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
  8.  
  9.     (Set "Operate=Endlocal ^& Set /A ""%%G%%H=%%I"""
  10.  
  11.     %= 'Tunnels' variable value, Allows Definition of Arithmetic within Macro =%)
  12.  
  13.     Set @M=for /L %%n in (1 1 2) do if %%n==2 (%\n%
  14.     for /F "tokens=1,2,3 delims=, " %%G in ("!argv!") do (%\n%
  15.     %Operate%%\n%
  16. %=  Display value of variable. Effective when Macro is accessed from code blocks =%
  17.     Call Echo(%%G: %%%%G%%%\n%
  18.     ) %\n%
  19. ) ELSE setlocal enableDelayedExpansion ^& set argv=,
  20.  
  21. REM macro can be used to define as well as modify variables
  22. REM output of macro can be redirected to nul (hidden) like so:
  23. REM (%@M% hp + 50)>nul
  24.  
  25. Setlocal EnableDelayedExpansion
  26.  
  27.     %@M% hp + 50
  28.     (%@M% heal + 30)>nul
  29.     %@M% hp - 30
  30. %= Multiple values / operations can be combined. Spaces Not Permitted =%
  31.     %@M% hp + 2*heal
  32.     %@M% hp * 2
  33.     %@M% hp / 3
  34.     %@M% hp + heal
  35.     %@M% heal - 10
  36.     %@M% hp + heal
  37.     For /L %%A in (1,1,300) do (%@M% hp + 1)>nul
  38.     Echo(hp: %hp%
  39. %= demonstrates variable is updated during code block operation =%
  40.     For /L %%A in (2,2,40) do (If not !hp! LSS 100 (%@M% hp - %%A))
  41.  
  42. pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement