I want to reset some variables when the user clicks on the "Return" or "Cancel" button. How can this be done?

You can do it with the following script commands:

On "/12" process="ClearSomeVariables.txt"

On "/15" process="ClearSomeVariables.txt"

where "ClearSomeVariables.txt" is an InputScript containing the variable reset commands.

But please observe that in most cases it is better to reset the variables when the user enters the transaction, not when he leaves it.