question about global var in plugin

Posted by Yeedoo on Tue 13 Mar 2012 03:20 AM — 3 posts, 14,370 views.

China #0
I defined a global var(a table) in my plugin script.
But every time i restart the world, The plugin keep those global var even i clear the 'save_state'.
I dont want the plug keep those global var.
My question is
1.how to make a clean plugin global namespace every time the plugin or the world restart.
2.Where are those plugin global var be stored?
Thank you!
Australia Forum Administrator #1
Some example code would help here.

Don't put variables into the plugin (in the <variable> part) because that will overwrite any variables saved in the state file.

If you have "save_state" set then each world/plugin combination saves its plugin variables into a file in the "state" subdirectory. The file name is a combination of the plugin ID and the world ID. eg.


a7046428ba477ebb729250df-d2fa45d390d935d947cdc169-state.xml

China #2
Nick Gammon said:

Some example code would help here.

Don't put variables into the plugin (in the <variable> part) because that will overwrite any variables saved in the state file.

If you have "save_state" set then each world/plugin combination saves its plugin variables into a file in the "state" subdirectory. The file name is a combination of the plugin ID and the world ID. eg.


a7046428ba477ebb729250df-d2fa45d390d935d947cdc169-state.xml



Thank you very much Nick.
I check the code, found that it load a serialized table into a global var from the state file every time the plug installed.
I have always thinked that the var stored in _G namespace could also be stored when i leaved the world.
and now i see, Only the var saved in the state file could be kept, Is that right?