Progressive compiling

Started by
0 comments, last by WitchLord 10 years, 6 months ago
Hi, here is the problem I want to find a solution. I want to dynamically edit a script file A, so I need to compile it again and again and see the running result. A requires some common functions and global variables that are stable and no need to change, more importantly, it always needs some data that need some time to calculate. Say these dependent function and variables are stored in script B. So it's better to load B first and let it do the calculation to prepare data and then load A to run it. In this way A can be changed and run without recalculate data in B. However I found that if there is some errors in A which makes the module fail to build, the modules will be "damaged" and those function/variables in B will also be destroyed and that will be contradicted to my initial purpose of doing so. Since all script entities are in modules, I cannot make them global. And right now importing global variable from another module is not supported. So is there any good solution to this? Thank you very much!
Advertisement

To make "hot loading" as easy as possible to implement you should try to abstract the script that can be modified "on the fly" as much as possible from the rest of the system.

Instead of directly reusing module A when recompiling the modified script, create a module C and compile it there first to check if the script doesn't have any errors.

If the compilation of module C is successful you can discard module A, then rename module C to module A. If the compilation is not successful you should obviously not discard module A.

If you have any values on global variables in script A that you want to keep after the recompilation, you should enumerate those before discarding the module and copy them over to module C.

If you have object instances of any classes declared in script A, you can use the serializer add-on to store these values and then re-create the instances with the new declaration from module C.

Observe that any script entities declared as 'shared' will not be recompiled if anything is still referring to them, so these cannot be modified "on the fly" like this. If you need to modify 'shared' script entitites then you need to release all script objects, discard all modules, then recompile all from scratch, and finally recreate the script objects with whatever was backed up.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement