T3RRYT3RR0R

PotionExample

Jun 13th, 2026 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.34 KB | Software | 0 0
  1. @Echo off
  2. REM Example of using conditional operations to implement control of logic flow in a codeblock without requiring Delayed expansion.
  3.  
  4. REM clamp macro Authored by IcarusLives and Aacini
  5. REM clamp Usage: || Set /a "x=VarToClamp, low=minValue, high=maxValue, VarToClamp=%clamp%"
  6. REM %= UseIF delayedExpansion enabled  =%  Set "clamp= (leq=((low-(x))>>31)+1)*low  +  (geq=(((x)-high)>>31)+1)*high  +  ^^^!(leq+geq)*(x) "
  7.     %= UseIF delayedExpansion disabled =%  Set "clamp= (leq=((low-(x))>>31)+1)*low  +  (geq=(((x)-high)>>31)+1)*high  +  !(leq+geq)*(x) "
  8.  
  9. Set /a maxHP=120,^
  10.        hp=50,^
  11.        potioncount=5,^
  12.        healAmount=10,^
  13.        maxPotionCount=10,^
  14.        maxCarried=25
  15.  
  16. :example
  17. Choice /n /c:ue /M "[U]se potion [E]xit"
  18. If errorlevel 2 Goto:Eof
  19. Call:usePotion
  20. Goto:example
  21.  
  22. :usePotion
  23.   If %hp% GEQ %maxHP% (
  24.     Echo(Already at full life
  25.     Exit /b 0
  26.   )
  27.  
  28.   2> nul (%= uses supressed divide by zero error to implement control flow logic with conditional operands =%
  29.     Set /a "x=hp","low=hp + ((potionCount/potionCount)*healAmount)","high=maxHP","hp=%clamp%" && (
  30.       Call Echo HP: %%hp%%
  31.     ) || (
  32.       Echo You have no potions.
  33.       Exit /b 0
  34.     )
  35.   )
  36.   For %%G in (potionCount Carried) Do Set /a "x=%%G-1","low=0","high=max%%G","%%G=%clamp%"
  37.   Echo( Potions remaining: %potionCount%
  38.   Echo(
  39. exit /b 0
Tags: batch
Advertisement
Add Comment
Please, Sign In to add comment