"Stop the code" bumper

The kids are interested in having a bumper to kill the code, but I don’t think there’s any elegant way to do this in blocks.

We could put the code in a repeat 1 loop, then do a “if bumper is pressed, break” after every block. But that would be a hot mess. There also could be a boolean that would switch, but that would still require a bulky check after every line. Is there some more elegant way to do a kill switch in blocks?

What about this, for every button function, nest the normal code inside an if statement.

If control variable is = 1, then… button commands
else stop

have the bumper in a separate forever loop that sets control variable to 0 while pressed.

Sorry, this is for auto, where there are like 30ish lines of code. So I would need to “check” after each block. In text, I could just put it to the side on each line. In blocks, it’s going to get really annoying.

One option is to make myblock function with input parameters for moving straight and for turning and within the myblock have a condition that only runs the code if a certain boolean is true. You have a loop code looking for input to change the boolean to false via touch sensor or bump sensor. And in the main auto code section will be just a bunch of myblock calls for your auto. The myblocks itself will determine when the run code or not. I hope that helps.

Cheers.

1 Like