Log In  


Hi all,
just getting my feet wet with pico-8 even if I've programmed quite extensively over the years. So far I'm having a blast!

Now to the question:

Is it safe to remove elements from a table while traversing it?

foreach(actor,update_actor)

...

function update_actor(a)
 if(a.dead) delete(actor,a)
end

Or does the above skip elements?

Other option would be to mark elements for deletion and then make a delete sweep post the update calls.

Thanks!



Hi - yes that is safe - I normally use 'del' rather than delete - not sure if they're synonymous, since I'm a lazy programmer and didn't read the manual properly ..

function update_actor(a)
  if(a.dead) then del(actor,a) end
end

Thanks! Let's hope its just shorthand. :)



[Please log in to post a comment]