From 907b740c17a69a487126c63f6ff917d494a25a1f Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Fri, 13 Jul 2012 16:20:26 +0200 Subject: Fixed the atinit function Previously each map had its own scope. They got merged now but the atinit function was forgotten to adapt. --- scripts/lua/libmana.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'scripts/lua/libmana.lua') diff --git a/scripts/lua/libmana.lua b/scripts/lua/libmana.lua index d133e574..5d3164d9 100644 --- a/scripts/lua/libmana.lua +++ b/scripts/lua/libmana.lua @@ -89,7 +89,9 @@ end -- Registers a function so that is 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 -- cgit v1.2.3-70-g09d2