How to put a delay on factory?(SOLVED)

This is my code for factory:

function update(self, dt)
	if copy <20 then
		local pos = vmath.vector3(math.random(108, 1673), 147, 0)
		factory.create("#factory", pos)
		copy = copy +1
	end
end

How can I make my factory to wait few (5-15) seconds until it creates new copy of the prototype?

maybe Defold Timer is good thing to use, I’m new to Defold too, maybe i can’t give you good complete code about it but i think you can do it yourself if you use timer

4 Likes

Yes, excellent choice!

	function init(self)
		-- call the provided function every 5 seconds
		timer.delay(5, true, function()
			local pos = vmath.vector3(math.random(108, 1673), 147, 0)
			factory.create("#factory", pos)
		end)
	end
2 Likes