How do you use this block
@Richard I’ve heard you touch the topic on stream a few times but I can recall what you said. Could you give me a quick explanation on how to use it/how it works?
Thanks in advance
-pecan4
How do you use this block
@Richard I’ve heard you touch the topic on stream a few times but I can recall what you said. Could you give me a quick explanation on how to use it/how it works?
Thanks in advance
-pecan4
The Block runs an endless loop until the Boolean condition is marked as false.
Whatever is in the block will run endlessly until same thing stated above.
Think of it as a “forever” block that has a “IF” statement inside of it:
From what I know, the difference is that the forever will not pause your game and will always check for that condition while the “While true” block will only check when you call / run it and does pause your game until the loop is over.
I hope this helps out a bit while waiting for Richard ahahah.
basically it repeats whatever is inside of it until the condition is met or a break is used inside of the loop.
yep! these explanations are pretty much correct!
the while loop is a loop that keeps executing until the boolean expression you pass in evaluates to false, as opposed to for-loops which just run a set number of times.
i like to think of while loops as the most basic kind of loop. it doesn’t do anything automatically for you like for-loops do, but you can make any other kind of loop by using one (and more!). for example, take this for loop:
i can make a while loop that does the same thing like this:
but that’s a pretty boring example since you could just use a for-loop to do the same thing. while-loops let you control the condition that keeps them running, so you can do a lot more complex tasks.
for example, check out this dumb project:
in this project i have a while loop that spawns sprites as long as the “faucetOn” variable is set to true. when you press A, the “faucetOn” variable becomes false and the while loop stops.
the one danger of using while loops, as @Reznolv touched on, is that they will freeze your game if they never exit and you don’t pause inside them. take the pause block out of the faucet example and you’ll see the game freeze
To clarify what I was asking; I know what is supposed to do, I just know that it freezes the game sometimes so I was wondering how to not do that (which richard answered). Thanks to everyone who helped!
Also keep in mind that these also may loop when your in the menu, like in @richard 's faucet project, if you pause into the menu, the water comes from nowhere!