Stopping Loops with a Button

Hi Peoples!
So, I made a loop that starts when the user presses the start button then it completes an action then waits for 10000 milliseconds before doing it again. And I want to make the loop stop when the user presses the stop button, but I was confused about the break block. Do you have to put it inside the same loop that you want to stop, or can it be anywhere on the board? If so does it have to specify which loop it is referring to? Or is there a different way to do this?
Thanks for reading! (。・ω・。)

Please show your relevant blocks so far....

See http://josmasflores.blogspot.com/2013/02/a-single-thread-of-execution-in-app.html
from
FAQ Section: Waiting and Timing

image

and your clock timer event block ?

what is that?

image

I thought I didn't need one because it's a loop

Your blocks are not a loop, it will only send a message once on button click if the location address condition is met, which is unlikely because location address is not a number.

Are you also intending for this to work in the background?

yes, let me try some other ways to make this work.

If your yes was about running in the background, you will need a background tasks extension for this - there is a paid and free extension for this, whether it will work with texting I do not know.

Here are some simple blocks that show how the clock timer works....

image

So hypothetically... would this work

oh wait, i need to add a new variable and set it to 0?

Just start the clock with your SendButton event, put everything else in the clock timer event. Set the clock timer to 10000 ms. Keep your StopButton blocks as they are.

like this?

image

1 Like

Bear in mind that the GPS will probably only update every 30 seconds, if you are lucky....You should probably use the LocationChanged event instead of a clock.

Ok, thank you so much :heart::heart::heart:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.