diff options
author | Rubenwardy <anjayward@gmail.com> | 2013-02-22 19:57:24 +0000 |
---|---|---|
committer | Rubenwardy <anjayward@gmail.com> | 2013-02-22 19:57:24 +0000 |
commit | aef2e2ae9131718ddc2033380179b5a719a18c2a (patch) | |
tree | f7acaa9a82a2ddfff11efd77722a36e04e4c22ab | |
parent | 2942ae602b1262748e6903a3bd33078879060f7e (diff) |
Add serialization
-rw-r--r-- | init.lua | 33 | ||||
-rw-r--r-- | triggers.lua | 4 |
2 files changed, 21 insertions, 16 deletions
@@ -4,27 +4,17 @@ -- this is the api definition file for the awards mod ------------------------------------------------------- --- The global award namespace -awards={} -player_data={} - --- A table of award definitions -awards.def={} - --- Load files -dofile(minetest.get_modpath("awards").."/triggers.lua") - -- Table Save Load Functions -local function save(table, file) - local file = io:open(file, "w") +local function save_playerD() + local file = io.open(minetest.get_worldpath().."/awards.txt", "w") if file then - file:write(minetest.serialize(table)) + file:write(minetest.serialize(player_data)) file:close() end end - -local function load(file) - local file = io:open(file, "r") + +local function load_playerD() + local file = io.open(minetest.get_worldpath().."/awards.txt", "r") if file then local table = minetest.deserialize(file:read("*all")) if type(table) == "table" then @@ -34,6 +24,15 @@ local function load(file) return {} end +-- The global award namespace +awards={} +player_data=load_playerD() + +-- A table of award definitions +awards.def={} + +-- Load files +dofile(minetest.get_modpath("awards").."/triggers.lua") -- API Functions function awards.register_achievement(name,data_table) @@ -55,6 +54,8 @@ function awards.give_achievement(name,award) if not data['unlocked'][award] or data['unlocked'][award]~=award then data['unlocked'][award]=award minetest.chat_send_player(name, "Achievement Unlocked: "..award) + + save_playerD() end end diff --git a/triggers.lua b/triggers.lua index 6d458f8..5f4b3b3 100644 --- a/triggers.lua +++ b/triggers.lua @@ -67,4 +67,8 @@ minetest.register_on_newplayer(function(player) --Table to contain achievement records player_data[player:get_player_name()]['unlocked']={} +end) + +minetest.register_on_shutdown(function() + save_playerD() end)
\ No newline at end of file |