storage-mod_storage.lua 966 B

12345678910111213141516171819202122232425262728293031323334
  1. -- ===================================================================
  2. -- /storage-mod_storage.lua
  3. -- Persistent storage via Minetest's mod_storage method
  4. -- See https://dev.minetest.net/StorageRef
  5. -- Loads content of stored orgs and ledger from mod_storage
  6. --get modstorageref
  7. local mod_storage = minetest.get_mod_storage()
  8. modpol.load_storage = function()
  9. -- load orgs
  10. local stored_orgs = minetest.deserialize(mod_storage:get_string("orgs"))
  11. if (stored_orgs ~= nil) then
  12. modpol.orgs = stored_orgs
  13. end
  14. -- load orgs
  15. local stored_ledger = minetest.deserialize(mod_storage:get_string("ledger"))
  16. if (stored_ledger ~= nil) then
  17. modpol.ledger = stored_ledger
  18. end
  19. end
  20. -- Stores content of current orgs and ledger to mod_storage
  21. modpol.store_data = function()
  22. -- write to storage
  23. mod_storage:set_string("orgs", minetest.serialize(modpol.orgs))
  24. mod_storage:set_string("ledger", minetest.serialize(modpol.ledger))
  25. end