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:
- defined a global _G.testVar in main.lua
- main.lua loads menu.lua
- menu.lua sets testVar=0 and loads game.lua
- game.lua increments the value of testVar and the reloads menu.lua
- If I print out the value of testVar in menu.lua it is 0.
- 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! [import]uid: 16901 topic_id: 18659 reply_id: 318659[/import]
[import]uid: 52491 topic_id: 18659 reply_id: 71787[/import]