agree, for me lua is mind bending
this example stores functions in a table using function name as 'index' and let's them execute later
Code:
spawnClocks = {}
function spawnBomber()
...
template.from(sharkBomberTemplate, worldContainer, params);
end
function setupSpawnClocks()
for k,v in pairs(spawnClocks) do v = nil end
if gameLevel==1 then
spawnClocks[spawnBomber] =
{
maxTime = 15,
minTime = 10,
timer = 4
}
end
end
function spawnEnemy()
for k,v in pairs(spawnClocks) do
v.timer= v.timer - deltaT;
if v.timer <=0 then
v.timer = math.random(v.minTime,v.maxTime)
k() --execute spawnBomber
end
end
return 1;
end
Bookmarks