I know the use of globals is frowned upon but I was meessing around with them and have observed some strange behavior. Just wondering if the following scenario makes any sense:
1. defined a global _G.testVar in main.lua
2. main.lua loads menu.lua
3. menu.lua sets testVar=0 and loads game.lua
4. game.lua increments the value of testVar and the reloads menu.lua
5. If I print out the value of testVar in menu.lua it is 0.
6. If I then reload game.lua the value of testVar is once again incremented... to 2. Shouldn't it just be 1? The global value was reset to 0 by menu.lua. It seems like a new instance of the global variable is created for each .lua file.
I can't figure out why I am seeing this behavior. Any help would be greatly appreciated! Thanks!