minetest.after

From Minetest Developer Wiki
Jump to: navigation, search

Contents

Syntax

minetest.after(time, function, param)

Description

This calls a function after time seconds. It can also be used to add a function to the end of the queue of functions becoming executed by minetest.
param is optional; to pass multiple parameters, pass a table.


after(1, funct() after(1, (funct() […] → the second function becomes executed > 1s after the first one

after(1, funct() […] after(2, (funct() […]

→ the second function becomes executed ca. 1s after the first one

Parameters

1: Time that has to pass for the function to be ran

2: Function

3: Optional - parameters to the function, use a list for multiple

Examples

local pos = {x=1,y=2,z=3}
local str = "hello world"
minetest.after(3.5, function(pos, str) 
    print("3.5 seconds later, we can do " .. str .. " at " .. minetest.pos_to_string(pos))
end, pos, str)
local player_visual_index = 0
function switch_player_visual()
	for _, obj in pairs(minetest.get_connected_players()) do
		if player_visual_index == 0 then
			obj:set_properties({visual="upright_sprite"})
		else
			obj:set_properties({visual="cube"})
		end
	end
	player_visual_index = (player_visual_index + 1) % 2
	minetest.after(1.0, switch_player_visual)
end
minetest.after(1.0, switch_player_visual)
minetest.after(0, function()
	print("First Environment step run")
end)
print("Mod initalized")
Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox