[SOLVED] How to create a queue of spawning game objects after one another and stopping based on a countdown timer

Oh, this is probably a very old version of Ludobits. The latest version has no timer/countdown module. There is no need for it since Defold has a built in timer nowadays. Here’s how I’d do it:

-- minigame.script

local function delete_object(self)
	if self.current then
		go.delete(self.current)
		self.current = nil
	end
end

local function create_object(self)
	-- make sure there is no object
	delete_object(self)
	self.current = factory.create("#factory")
end

function on_input(self, action_id, action)
	-- spawn a new item on each click/touch
	if action_id == hash("touch") and action.pressed then
		msg.post("/spawner", "spawn")
	end
end

function on_message(self, message_id, message, sender)
	if message_id == hash("start_minigame") then
		msg.post(".", "acquire_input_focus")
		create_object(self)
		timer.delay(8, false, function()
			msg.post("main:/main", "game_over")
		end)
	end
end
1 Like