Get rid of global variables mess

This commit is contained in:
Wuzzy 2016-11-09 06:10:44 +01:00
parent af8d1309bc
commit 02938f9808

View File

@ -7,7 +7,7 @@ local insecure_environment = minetest.request_insecure_environment()
-- entity management functions -- entity management functions
function save_entities() local function save_entities()
local entities = {} local entities = {}
local count = 0; local count = 0;
@ -60,11 +60,11 @@ function save_entities()
return count return count
end end
function get_saved_entities() local function get_saved_entities()
return tutorial.entities return tutorial.entities
end end
function load_entities() local function load_entities()
local entities = get_saved_entities() local entities = get_saved_entities()
local count = 0 local count = 0
@ -80,7 +80,7 @@ function load_entities()
minetest.log("action", "[tutorial] " .. count .. " entities loaded") minetest.log("action", "[tutorial] " .. count .. " entities loaded")
end end
function load_entities_area(minp, maxp) local function load_entities_area(minp, maxp)
if not tutorial.entities_cache then if not tutorial.entities_cache then
tutorial.entities_cache = get_saved_entities() tutorial.entities_cache = get_saved_entities()
@ -160,7 +160,7 @@ do
end end
end end
function save_schematic() local function save_schematic()
local success = true local success = true
for k,sector in pairs(tutorial.map_sector) do for k,sector in pairs(tutorial.map_sector) do
local filename = tutorial.map_directory .. "sector_"..k local filename = tutorial.map_directory .. "sector_"..k
@ -178,7 +178,7 @@ function save_schematic()
return success return success
end end
function load_schematic() local function load_schematic()
local success = true local success = true
for k,sector in pairs(tutorial.map_sector) do for k,sector in pairs(tutorial.map_sector) do
local filename = tutorial.map_directory .. "sector_"..k local filename = tutorial.map_directory .. "sector_"..k
@ -210,7 +210,7 @@ end
-- @param filename (without externsion) with the path to save the shcematic and metadata to -- @param filename (without externsion) with the path to save the shcematic and metadata to
-- @param slice_prob_list = {{ypos=,prob=}, ...} list of probabilities for the slices to be loaded (if nil, always load) -- @param slice_prob_list = {{ypos=,prob=}, ...} list of probabilities for the slices to be loaded (if nil, always load)
-- @return The number of nodes with metadata. -- @return The number of nodes with metadata.
function save_region(minp, maxp, probability_list, filename, slice_prob_list) local function save_region(minp, maxp, probability_list, filename, slice_prob_list)
local success = minetest.create_schematic(minp, maxp, probability_list, filename .. ".mts", slice_prob_list) local success = minetest.create_schematic(minp, maxp, probability_list, filename .. ".mts", slice_prob_list)
if not success then if not success then
@ -299,7 +299,7 @@ end
-- @param replacements = {["old_name"] = "convert_to", ...} -- @param replacements = {["old_name"] = "convert_to", ...}
-- @param force_placement is a boolean indicating whether nodes other than air and ignore are replaced by the schematic -- @param force_placement is a boolean indicating whether nodes other than air and ignore are replaced by the schematic
-- @return boolean indicating success or failure -- @return boolean indicating success or failure
function load_region(minp, filename, vmanip, rotation, replacements, force_placement) local function load_region(minp, filename, vmanip, rotation, replacements, force_placement)
if rotation == "random" then if rotation == "random" then
rotation = {nil, 90, 180, 270} rotation = {nil, 90, 180, 270}