Hello, as a result of writing the game I ran into a misunderstanding of spawning mobs with a certain cooldown. When using the code inside the function, its execution is instantaneous, at the same time I tried to use timer.delay, but nothing worked + when using it, monsters spawned and immediately disappeared.
function mobSpawn(self, wavePoint)
while(wavePoint > 0)
do
if wavePoint >= 5 then
local numMonster = math.random(1, 5)
wavePoint = wavePoint - numMonster
monster_name = monster_list[numMonster]
factory.create(monster[monster_name].factory_url, position, nil, {damage = monster[monster_name].damage, speed = monster[monster_name].speed, hp = monster[monster_name].hp, height = monster[monster_name].height, experience = monster[monster_name].experience})
else
local numMonster = math.random(1, wavePoint)
wavePoint = wavePoint - numMonster
factory.create(monster[monster_name].factory_url, position, nil, {damage = monster[monster_name].damage, speed = monster[monster_name].speed, hp = monster[monster_name].hp, height = monster[monster_name].height, experience = monster[monster_name].experience})
end
end
end
Here’s how I tried to implement .delay
{...}
if wavePoint >= 5 then
local numMonster = math.random(1, 5)
wavePoint = wavePoint - numMonster
monster_name = monster_list[numMonster]
timer.delay(1, false, function()
factory.create(monster[monster_name].factory_url, position, nil, {damage = monster[monster_name].damage, speed = monster[monster_name].speed, hp = monster[monster_name].hp, height = monster[monster_name].height, experience = monster[monster_name].experience})
end)
{...}