Members - Reputation: 118
Posted 07 October 2013 - 12:08 AM
Moderators - Reputation: 4221
Posted 07 October 2013 - 02:58 PM
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.
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game