forked from mtcontrib/awards
Move save function
This commit is contained in:
parent
6405b26d65
commit
9f61f2e600
13
api.lua
13
api.lua
@ -4,8 +4,11 @@
|
|||||||
-- this is api function file
|
-- this is api function file
|
||||||
-------------------------------------------------------
|
-------------------------------------------------------
|
||||||
|
|
||||||
|
-- The global award namespace
|
||||||
|
awards = {}
|
||||||
|
|
||||||
-- Table Save Load Functions
|
-- Table Save Load Functions
|
||||||
function save_playerD()
|
function awards.save()
|
||||||
local file = io.open(minetest.get_worldpath().."/awards.txt", "w")
|
local file = io.open(minetest.get_worldpath().."/awards.txt", "w")
|
||||||
if file then
|
if file then
|
||||||
file:write(minetest.serialize(awards.players))
|
file:write(minetest.serialize(awards.players))
|
||||||
@ -13,7 +16,7 @@ function save_playerD()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function load_playerD()
|
function awards.load()
|
||||||
local file = io.open(minetest.get_worldpath().."/awards.txt", "r")
|
local file = io.open(minetest.get_worldpath().."/awards.txt", "r")
|
||||||
if file then
|
if file then
|
||||||
local table = minetest.deserialize(file:read("*all"))
|
local table = minetest.deserialize(file:read("*all"))
|
||||||
@ -24,9 +27,7 @@ local function load_playerD()
|
|||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- The global award namespace
|
awards.players = awards.load()
|
||||||
awards={}
|
|
||||||
awards.players=load_playerD()
|
|
||||||
function awards.player(name)
|
function awards.player(name)
|
||||||
return awards.players[player]
|
return awards.players[player]
|
||||||
end
|
end
|
||||||
@ -175,7 +176,7 @@ function awards.give_achievement(name,award)
|
|||||||
print(name.." Has unlocked"..title..".")
|
print(name.." Has unlocked"..title..".")
|
||||||
|
|
||||||
-- save playertable
|
-- save playertable
|
||||||
save_playerD()
|
awards.save()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -188,5 +188,5 @@ minetest.register_on_newplayer(function(player)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_shutdown(function()
|
minetest.register_on_shutdown(function()
|
||||||
save_playerD()
|
awards.save()
|
||||||
end)
|
end)
|
Loading…
Reference in New Issue
Block a user