Cancel a run up button action

Hello, when I toggle to off a button I would like to stop the run. I tried this (see attached) but the script variable seem to be removed. Any suggestion?

cancellable_run.toe (17.2 KB)

def onValueChange(channel: Channel, sampleIndex: int, val: float, 
                  prev: float):
	global run_obj
	if (val == 1.0):
		run_obj = run('print("Hello")', delayMilliSeconds=5000)
	else:
		run_obj.kill()
		
	return

You just need to let Python know run_obj is global

1 Like