Is there something you're supposed to write in for blender scripts in BGE?
here's my code, it runs and does what I want it to... only after I've closed BGE which noone else seems to have run into.


Your code is Blender code rather than BGE code.

You basically tell Blender what to do. But you want running a BGE game session. 

BGE behavior is setup via Logic Bricks (Logic Editor). You can create a custom Controller brick. It refers to a text block (script mode/module mode) or an external python file (module mode). 

The code should not refer to Blender (do not import bpy). When you distribute your game Blender will not be available and running such code will result in errors.

More information can be found at Blenderartists.org. E.g. The BGE Guide to Python Coding

Just to let you know: The BGE does not support mesh creation. All objects and meshes must be loaded either at startup or via Python code while running the game. You can make copies of loaded objects as long as they are inactive (reside on an hidden layer).