Hello,
I have a factory which creates every X second a game object in a liste of positions possible. I used a recursive function to spawn each elements but nothing gets created. That’s my piece of code:
local spawned = { nil, nil, nil, nil, nil, nil, nil }
function spawn(position)
position_id = math.random(table.getn(positions)) -- position is an array of coordinates
if spawned[position_id] ~= nil then
position.x = positions[position_id][1] -- position is declared with local in update() and has the value: go.get_position()
position.y = positions[position_id][2]
position.z = 1
spawned[position_id] = true
return { position, position_id }
else
spawn(position)
end
end
From test I made, it seems that it nevers gets in the if
but gets into the else
, creating an infinity loop.
Thanks!