Good question. I had never done this till today, but this is at least one way to do it. You can create your variables in the mathscript node and mathscript Window and bring them back and forth by using the load and save commands.
For example create something in Mathscript Window. Go to File-> Save Data... and save the file to a .mlv file. Then open the mlv in Mathscript Node by using "load '<file path>'" in the first line of the node. Tested it and it worked for me. You can also use the "save <file path>" to get it back to the Mathscript window.
I am not really sure what you are trying to do in the second part of your question. How exactly are you initializing the mathscript node, and where exactly do you think the error is occuring?