User Tools

Site Tools


4rpl:commands:while

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
4rpl:commands:while [2021/01/08 11:01] – external edit 127.0.0.14rpl:commands:while [2024/06/05 22:21] – [Examples] Added a unit-script example. LiteralNoob
Line 1: Line 1:
 ~~NOTOC~~ ~~NOTOC~~
-<=[[4rpl:start| Index]]+<= [[4rpl:start| Index]] \\ 
 +<= [[4rpl:start#Flow Control]]  
  
 ====== while ====== ====== while ======
Line 12: Line 14:
 ===== Examples ===== ===== Examples =====
 <code 4rpl> <code 4rpl>
 +# CONSOLE SCRIPT
 5 ->y 5 ->y
 while   <-y gt(0)    #is y greater than zero? while   <-y gt(0)    #is y greater than zero?
Line 17: Line 20:
     trace(<-y)     trace(<-y)
     <-y sub(1) ->  #subtract 1 from y so we don't end in infinite loop     <-y sub(1) ->  #subtract 1 from y so we don't end in infinite loop
 +endwhile
 +</code>
 +<code 4rpl>
 +# UNIT SCRIPT
 +
 +# This script increases the max health of the unit over time.
 +# The script won't be stuck in the loop since it's limited by the unit's
 +# Health regen rate or "GetUnitHealRate(self)".
 +
 +while(GetUnitHealth(self) GetUnitMaxHealth(self) eq)                    #If unit's current health is equal to it's max health...
 +    repeat                                                              #...repeat this section of code.
 +    SetUnitMaxHealth(self GetUnitMaxHealth 0.5 add)                     #Add 0.5 points of max health to the unit
 +    SetUnitDebugText(self Concat("Max Health: " GetUnitMaxHealth(self)) #Visual aid for you to know.
 endwhile endwhile
 </code> </code>
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
  
4rpl/commands/while.txt · Last modified: 2024/06/11 12:16 by Kalli