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?



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

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.


P#27544 2016-08-28 12:15 ( Edited 2016-08-28 16:31)

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
P#27545 2016-08-28 12:22 ( Edited 2016-08-28 16:22)
:: johanp

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

P#27549 2016-08-28 12:31 ( Edited 2016-08-28 16:31)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-08-06 12:23 | 0.008s | 2097k | Q:14