From 05f3249e17121dc79e447b878cbd54e4d51dcdef 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. Reviewed-by: bjorn. --- scripts/lua/libmana.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'scripts/lua/libmana.lua') diff --git a/scripts/lua/libmana.lua b/scripts/lua/libmana.lua index d133e57..0636e49 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 -- cgit