Is there any scenario where its better than simply checking condition for something and going with some action
And/or scenario where its absolutely needed and i can’t go without it?
I mean like
Yesterday a user came to discord with problem where he looped it to infinity and beyond
And his preview did not want to run
I suspected while events to be responsible and turned out they were
I told him not to worry cause i am over 3 years here and never used them and for sure he don’t need to also
BUT that was maybe just lack of me finding myself in such situation and i was wrong about it
So i wonder if either its absolutely needed in some scenarios or better in some?
The while event is handy in certain situations. It’s tricky because it can also create infinite loops and things that happen between frames don’t get updated within it.
The array tools extension is good for searching arrays but if you had a more complex array like something with structures, you could use a while event to go through an array and stop when an item was found. This could be a time saver if used with a huge array. It wouldn’t have to search the entire array each time. You could use for each child with a smaller array or maybe Javascript.
Another example is a check routine for the classic pipe puzzle game. You can use an array to check if the water reaches the target tile(s).
First you start the array with the ID or position of the first tile. You then use a while event with the condition “number of children in the array is greater than zero” and a boolean like endReached is false.
Each time you remove the last element and use either an ID or position to check the adjacent tiles around it. If the pipe ends on the adjacent tiles match then you add those tiles to the array and mark the tiles as checked or an object variable like hasWater is true.
This continues until there are no more elements left in the array or a target tile is reached.
Think of the array as a buffer. It holds IDs or structures of the position of puzzle tiles and continues until the buffer is empty.
I used a similar approach for an electrical puzzle. It was simplier because the orientation of the pipes didn’t matter. It checked if sprites with a battery icon, wire, switch or lightbulb were adjacent. It then changed the lightbulb to lit if a path was found.
Yes, there are other ways to solve these puzzles but the while event keeps the processing to its events and subevents. It’s similar to a for each child or for each object but is a bit more efficient with a large number of items or objects because you can exit the loop when something is found. You can also extend the looping or jump around non-sequentially.
I personally don’t use it often but there are times when it’s useful and more efficient or flexible.
OK THX for that cause i was looking at it as useless garbage but now it does feel like useful tool
BUT i still can’t resist myself from thinking about it like i could achieve exactly that
With just conditions and actions
Same for your example with looping trough array
I could simply add condition to repeat for each child var if such child was not found
Or did i understand it wrong?
I mean in the end i do need additional condition
But i do get that without that condition it would be perfectly doable with WHILE event
I mean in my eyes WHILE event feels like overcomplicating stuff for sake of using this event
And not as making something easier way
On one hand i know A LOT of ppl who are perfectly capable of filtering something spamming itself over and over when they want it to spam with proper conditions
On other hand i don’t know many ppl who use WHILE event
So it would feel to me like learning how and when to use it
For sake of using it
And not because you either lack the knowledge how to do something without it and/or the way you are doing it right now is not worse than using WHILE event
You could use repeat or for each child but with repeat, there wouldn’t be a way to exit the loop early. It’s not an issue with 100 elements but say you had 1,000 elements. If you found your match at say element 200, you would still have to go through the other 800 elements. Although, if you used a boolean variable, you could use it to skip over most of the sub events and only process the boolean check.
Set found to false
Repeat 1000 times
… If found is false
… … compare something to something
… … Set found to true
Another option would be to split the array into smaller chunks like A thru l and M thru Z. There are always multiple ways of doing things.
As far as my puzzle checker, I’m not aware of an easier way using an array. For each child goes sequentially plus the array keeps getting elements added and removed. So, you wouldn’t know how many repeats are needed.
You couldn’t use repeat because the number of needed loops is unknown. It depends on where the objects are placed and their animations.
Again, the puzzle example could be done differently. Maybe by using the linked object behavior.
I miss understood your array comparison
I am aware for each child would need to run fully
And condition would just limit does it repeat or not
While WHILE event would stop as soon as its not true
So when working with tons of objects it really would be life saver for performance
HOWEVER my statement would kinda still stand
LION SHARE of users would never need it
Even better most likely no new user would need it
It would be required for some more fancy stuff