To make this easier to see I put the timer in the function as opposed to calling it outside the function. But they both result in the same issue. If I have two objects combine before the timer delay ends then my call to spawnVeggie doesn’t work. However, if I set it to True (on repeat timer) it will keep on spawning). I need a delay on the spawning, but if I don’t delay the spawn this issue doesn’t occur. it appears somehow the timer is being stopped/deleted by having the object it last spawned be deleted.
-- function to create one of 4 random starting veggies
function spawnVeggie(position)
if gameover == false then
-- Start the timer to let veggie fall so they don't collide with existing and new object
timer.delay(spawn_wait, false, function()
--local rot = vmath.quat(0, 0, 0, 50)
local rot = nil
local random_index = math.random(1, #factories)
local selected_factory = factories[random_index]
-- Spawn an object from the selected factory
if selected_factory == "greenpepper" then
local objectID = factory.create("main:/factories#startgreenpepperfactory", position, rot, nil, .2)
elseif selected_factory == "chilipepper" then
factory.create("main:/factories#startchilipepperfactory", position, rot, nil, .2)
elseif selected_factory == "redonion" then
factory.create("main:/factories#startredonionfactory", position, rot, nil, .13)
elseif selected_factory == "radish" then
factory.create("main:/factories#startradishfactory", position, rot, nil, .13)
end
end)
end
end