diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-07-13 16:20:26 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-08-05 23:18:57 +0200 |
commit | 05f3249e17121dc79e447b878cbd54e4d51dcdef (patch) | |
tree | 2e7e3805ebb09d6d87243791d0c0d7731fbe2308 /scripts/lua/libmana.lua | |
parent | 7e77328d1b9f35ed542dd3cfceadb1eb41f54afe (diff) | |
download | manaserv-05f3249e17121dc79e447b878cbd54e4d51dcdef.tar.gz manaserv-05f3249e17121dc79e447b878cbd54e4d51dcdef.tar.bz2 manaserv-05f3249e17121dc79e447b878cbd54e4d51dcdef.tar.xz manaserv-05f3249e17121dc79e447b878cbd54e4d51dcdef.zip |
Fixed the atinit function
Previously each map had its own scope. They got merged now but the atinit
function was forgotten to adapt.
Reviewed-by: bjorn.
Diffstat (limited to 'scripts/lua/libmana.lua')
-rw-r--r-- | scripts/lua/libmana.lua | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/scripts/lua/libmana.lua b/scripts/lua/libmana.lua index d133e574..0636e491 100644 --- a/scripts/lua/libmana.lua +++ b/scripts/lua/libmana.lua @@ -87,9 +87,11 @@ local function mapupdate(mapid) check_schedule(mapid) end --- Registers a function so that is is executed during map initialization. +-- Registers a function so that it is executed during map initialization. function atinit(f) - init_fun[#init_fun + 1] = f + local map_id = get_map_id() + init_fun[map_id] = init_fun[map_id] or {} + table.insert(init_fun[map_id], f) end -- Called by the game for creating NPCs embedded into maps. @@ -105,10 +107,12 @@ end -- Called during map initialization, for each map. -- Executes all the functions registered by atinit. local function map_initialize() - for i,f in ipairs(init_fun) do + local functions = init_fun[get_map_id()] + if not functions then return end + for i,f in ipairs(functions) do f() end - init_fun = {} + init_fun[get_map_id()] = nil end |