Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Echo off
- REM Example of using conditional operations to implement control of logic flow in a codeblock without requiring Delayed expansion.
- REM clamp macro Authored by IcarusLives and Aacini
- REM clamp Usage: || Set /a "x=VarToClamp, low=minValue, high=maxValue, VarToClamp=%clamp%"
- REM %= UseIF delayedExpansion enabled =% Set "clamp= (leq=((low-(x))>>31)+1)*low + (geq=(((x)-high)>>31)+1)*high + ^^^!(leq+geq)*(x) "
- %= UseIF delayedExpansion disabled =% Set "clamp= (leq=((low-(x))>>31)+1)*low + (geq=(((x)-high)>>31)+1)*high + !(leq+geq)*(x) "
- Set /a maxHP=120,^
- hp=50,^
- potioncount=5,^
- healAmount=10,^
- maxPotionCount=10,^
- maxCarried=25
- :example
- Choice /n /c:ue /M "[U]se potion [E]xit"
- If errorlevel 2 Goto:Eof
- Call:usePotion
- Goto:example
- :usePotion
- If %hp% GEQ %maxHP% (
- Echo(Already at full life
- Exit /b 0
- )
- 2> nul (%= uses supressed divide by zero error to implement control flow logic with conditional operands =%
- Set /a "x=hp","low=hp + ((potionCount/potionCount)*healAmount)","high=maxHP","hp=%clamp%" && (
- Call Echo HP: %%hp%%
- ) || (
- Echo You have no potions.
- Exit /b 0
- )
- )
- For %%G in (potionCount Carried) Do Set /a "x=%%G-1","low=0","high=max%%G","%%G=%clamp%"
- Echo( Potions remaining: %potionCount%
- Echo(
- exit /b 0
Advertisement
Add Comment
Please, Sign In to add comment