Loops
Tick loops
Section titled “Tick loops”In PPL, for updating every tick, pewpew.add_update_callback is used. Hybroid Live wraps it in a tick statement.
tick { Pewpew:Print("I am printed every tick!")}It is possible to create a tick statement with a time variable.
tick with time { Pewpew:Print(time .. " has elapsed")}While loops
Section titled “While loops”In Hybroid Live and PPL while loops are discouraged. However, you can still use them if you want or need to.
while true { Pewpew:Print("Running infinitely and as fast as possible!")}Repeat loops
Section titled “Repeat loops”Repeat loops are simple for loops.
repeat 10 { Pewpew:Print("Hybroid Live is awesome!")}It is possible to create a repeat loop with an iteration variable.
repeat 10 with index { Pewpew:Print("This is " .. index .. "th iteration!") // -> This is 1th iteration!}You can also specify the skip amount and the range, just like in Lua.
repeat by 2 from 4 to 10 with index { Pewpew:Print("This is " .. index .. "th iteration!") // -> This is 4th iteration!}For loops
Section titled “For loops”for loops are designed for advanced iterations.
let fruits = ["banana", "kiwi", "apple", "pear", "cherry"]
for index, fruit in fruits { Pewpew:Print(fruit .. " at index " .. ToString(index))}You also have the option to ignore one of the variables by leaving a discard identifier (_) in there.
let fruits = ["banana", "kiwi", "apple", "pear", "cherry"]
for _, fruit in fruits {// ignores the index Pewpew:Print(fruit)}
for index in fruits {// ignores the value Pewpew:Print(index)}Entity iteration (every)
Section titled “Entity iteration (every)”You can iterate through all active instances of a specific entity type using the every keyword:
for enemy in every Quadro { enemy.Damage(2)}Note: the entity type has to have originated from an entity declaration. You cannot iterate over all motherships, for example, because they’re not hybroid entities.
Break and continue
Section titled “Break and continue”Use break to exit a loop early and continue to skip to the next iteration:
repeat fruits_len with i { if fruits[i] == "kiwi" { continue // skip kiwis } if fruits[i] == "cherry" { break // stop at cherries } Pewpew:Print(fruits[i])}