I hope this script helps!

To convert back, just use an If.

Of course, the Tru variable can have any name, and you don't have to use a Touch Sensor for this. You can use any block that gives an execution order signal (that isn't an After signal, of course).