I found another issue with this function. Had to change the line:
minetest.timers[index] = nil
to:
table.remove(minetest.timers,index)
and it worked.
here is the full code:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.timers_to_add = {}
minetest.timers = {}
minetest.register_globalstep(function(dtime)
for _, timer in ipairs(minetest.timers_to_add) do
table.insert(minetest.timers, timer)
end
minetest.timers_to_add = {}
for index, timer in ipairs(minetest.timers) do
timer.time_sec = timer.time_sec - dtime
--print("Timer: "..index.." "..timer.time_sec)
if timer.time_sec <= 0 then
timer.func(timer.params)
--minetest.timers[index] = nil
table.remove(minetest.timers,index)
end
end
--print("Timer count: "..table.maxn(minetest.timers))
end)
function minetest.after(time_sec, func, params)
table.insert(minetest.timers_to_add, {time_sec=time_sec, func=func, params=params})
end
By-the-way, here it the code I'm using this for now:
It fills the air holes you see in water. It needs to be run after the normal register_on_generated because of some issue with dungeons.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
function CheckForWaterHoles(params)
minp = params.minp
maxp = params.maxp
for x = minp.x,maxp.x do
for z = minp.z,maxp.z do
for y = minp.y,maxp.y do
pos = {x=x, y=y, z=z}
pos_up = {x=x, y=y+1, z=z}
pos_down = {x=x, y=y-1, z=z}
if minetest.env:get_node(pos).name == "air" and minetest.env:get_node(pos_up).name == "default:water_source" then
minetest.env:add_node(pos, {name="default:water_source"})
doing_next_check = true
end
if minetest.env:get_node(pos_down).name == "air" and minetest.env:get_node(pos).name == "default:water_source" then
minetest.env:add_node(pos_down, {name="default:water_source"})
doing_next_check = true
end
end
end
end
end
minetest.register_on_generated(
function(minp, maxp)
minetest.after(10, CheckForWaterHoles, {minp=minp, maxp=maxp})
end)