That won't change anything you save variables to disk or they will be part of environment. Problem with true, false in function I just solved other way to stop script and continue it, and it's not something I thought up, but xbytor2 so you should ask for him or someone who uses such scripts. If you kept functions in your script but didn't post them here and getting error that function doesn't exist then investigate why that happen. I can not be any of help when I don't see code.
The basic problem is Action stop brake the action into parts. Each part is player by the user clicking the play button to play the next part of the action and the same document need to be the active document in the right state.
The easiest way to convert this type of action to a script is use X's action file to script then brake the script produced into the Action Parts. If there are two stops in an action there would be three scripts. ActionPart1 ActionPart2 ActionPart3. Instead of clicking the Play button to play the next part of the action you run the next script part.