Stopping a loop at the press of a button

Hey all,

I am having trouble making this block respond the way I need it to. Any help is appreciated!

This is the overall block. It is the meat and potatoes of a project I am working on.

My problem is with this section below. I would like it to stop as soon as the overall loop is called again (at the press of a button). I have tried to use the “break out of loop” block, but I haven’t gotten it to work the way I want to. If you see a way to achieve this, please let me know.
Screen Shot 2020-08-07 at 4.24.11 PM

Hey @luke.hall_2116, welcome to the Community :wave:

Using the forever block and a variable, this can be easily achieved.
image

Example

See these blocks as an example. Here I am adding random numbers to a list, and when I want it to stop, I press the button.

I wouldn’t quite understand how to integrate this directly into your app without a project link of some description, though this doesn’t seem too difficult to implement based on the blocks you’ve provided.

If you’ve any bother with this, just drop a reply here :slight_smile:

1 Like

Thank you, I hadn’t thought of that before. This may be an obvious question, but I haven’t used functions or forever loops much:

Would there be a way to stop this after a certain number of repeats?

In this case, it could be stopped if the larger event were called again (entire block in first screenshot), but would definitely stop after looping 14 times (as i showed in the second screenshot). Clear as mud?

You sure can!

This will repeat 10 times, unless it is stopped. If I were to start this again by clicking the Start Button then it would repeat it another 10 times. Is this what you would like?

Functions are great, and actually very easy to use with Thunkable. Check out the docs on Functions.

1 Like

Many thanks for the solution. If you’re up for it, another problem has popped up in it’s wake.

This new issue comes as a result of the repeat block continuously going in the background. If events happen fast enough, an old call of the function will register that the variable has changed back, and events will happen from both the new function being called, as well as the old one.

I need the function to completely stop once the variable tells it to. That way, it won’t interfere if the function is called again

Hi @luke.hall_2116,

Breaking a loop should jump to the next line of code, or at least that is the intended idea of a break.

Do you mind sharing some screenshots just highlighting the misfitting blocks? If you think it’s an issue of the loop going too fast you can add a wait block. Do keep in mind if a block has a then do at the end, this usually means the block may take extra time to execute. In this scenario, you should use the then do option, unless intended otherwise.

All the best, Eoin.

This issue is directly related to my previous question. It is the need for an edited solution to what was answered on this thread. This is what I ended up with after your solution:

It worked like a charm, except for some timing.

For the sake of understanding, I’m referring to the calling of function “load_Bar”, as well as the function itself running. Let’s say it is called once. It checks 14 times if it needs to break the cycle, and each is spaced out by a variable wait, which will decrease as time goes on (to make the game harder). It starts at .5 seconds. If the function is called a second time before the total wait (7 seconds) is up, the new instance of the function will work (because it has just been called) in addition to the old instance of the function (which senses that the variable {break_Loading_Bar_Cycle} has opened the loop again). Therefore, the results will be doubled. This is bad.

I need a solution that as soon as the variable {break_Loading_Bar_Cycle} says so, that instance of the function “load_Bar”, or included loop, is permanently closed to make room for the new one.

Thanks, Luke

Hi @luke.hall_2116,

Firstly, I do not understand how this could work:


The loop here would do nothing.


Did you try to use the break loop block to break the loop?
image

I was messing around with other solutions, and the block got reset. In the “load_Bar” function, it should repeat if “break_Loading_Bar_Cycle ≠ true”

I have messed around with the break loop, but nothing worked. Thunkable Docs say nothing about it, and I’ve never actually seen it successfully used.

If you have any examples or descriptions, that would be very helpful.

Thanks, Luke

Hi @luke.hall_2116,

Could you PM me a project link with information such as which screen this is on so i can take a closer look. Only if this is possible, Thanks.