# Build -> Build -> Build and kill all global variables :(

This topic is 2434 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

[font="arial, sans-serif"]Hi all, sorry for my english - use google.translate[/font]

[font="arial, sans-serif"]Next problem, I have 3 scripts.( it is exemple... )[/font]

[font="arial, sans-serif"]
root.as int exemple_gloval_var = 1; script_1.as #include "root.as" void main(){ exemple_gloval_var = 10; ... } script_2.as #include "root.as" void main(){ print( exemple_gloval_var ); }
[/font]

[font="arial, sans-serif"]and I need to compile them, but not all at once.[/font]
[font="arial, sans-serif"]When the game starts, it compiles the script 2.[/font]

[font="arial, sans-serif"]and running.[/font]

[font="arial, sans-serif"]time passes, I need a script 3, the game loads it, and compiles.[/font]
[font="arial, sans-serif"]This compilation will kill all global functions.[/font]

[font="arial, sans-serif"]I need it to not kill them[/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"]I understand that I can compile all scripts at once, but it's bad, I want to compile as needed.

I also understand that I can use different modules, it is not appropriate, I have to use one global module

##### Share on other sites
Why not just compile them at one time, unless you are working in extremely low memory situations. In that case, you may want to rethink using a scripting language altogether.

##### Share on other sites
Currently the only way you can keep the global variables between recompilations is by serializing them, i.e. before the recompilation you enumerate all the global variables and store their values, then after the recompilation you enumerate the variables again and restore their previous values.

##### Share on other sites
What I actually do in my engine is I use the 'any' type and the boost unordered_map and hash the values to strings somewhere in the engine's global scope. Still have no idea what it does to the reference counting, but it is something you could consider.

##### Share on other sites

Currently the only way you can keep the global variables between recompilations is by serializing them, i.e. before the recompilation you enumerate all the global variables and store their values, then after the recompilation you enumerate the variables again and restore their previous values.

[font=arial, sans-serif][size=2]Please look at this topic, there is a code - like I restore global variables. But I have a problem with asTYPEID_OBJHANDLE.[/font]