From 9f61f2e600281286fda4a059250ece78e4f79807 Mon Sep 17 00:00:00 2001 From: Rubenwardy Date: Wed, 6 Nov 2013 19:36:49 +0000 Subject: [PATCH] Move save function --- api.lua | 15 ++++++++------- triggers.lua | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/api.lua b/api.lua index 94756ff..23de354 100644 --- a/api.lua +++ b/api.lua @@ -4,8 +4,11 @@ -- this is api function file ------------------------------------------------------- +-- The global award namespace +awards = {} + -- Table Save Load Functions -function save_playerD() +function awards.save() local file = io.open(minetest.get_worldpath().."/awards.txt", "w") if file then file:write(minetest.serialize(awards.players)) @@ -13,7 +16,7 @@ function save_playerD() end end -local function load_playerD() +function awards.load() local file = io.open(minetest.get_worldpath().."/awards.txt", "r") if file then local table = minetest.deserialize(file:read("*all")) @@ -24,15 +27,13 @@ local function load_playerD() return {} end --- The global award namespace -awards={} -awards.players=load_playerD() +awards.players = awards.load() function awards.player(name) return awards.players[player] end -- A table of award definitions -awards.def={} +awards.def = {} function awards.tbv(tb,value,default) if not default then @@ -175,7 +176,7 @@ function awards.give_achievement(name,award) print(name.." Has unlocked"..title..".") -- save playertable - save_playerD() + awards.save() end end diff --git a/triggers.lua b/triggers.lua index 63fb9dc..b13ff93 100644 --- a/triggers.lua +++ b/triggers.lua @@ -188,5 +188,5 @@ minetest.register_on_newplayer(function(player) end) minetest.register_on_shutdown(function() - save_playerD() + awards.save() end) \ No newline at end of file