invalid key to 'next'

hi
I’m iterating through a table of objects and a lot of stuff happens to each object (moving around, hit tests etc)

for i, val in pairs(objTable) do   
 -- a lot of stuff happens  
end  

sometimes an error appears at that line:

Runtime error  
 invalid key to 'next'  
stack traceback:  
 [C]: ?  
 [C]: in function '(for generator)'  

my guess is, that an object is removed while the for loop tries to access it… :confused:
but what exactly does that message mean? and how can I prevent it?

-finefin
[import]uid: 70635 topic_id: 31034 reply_id: 331034[/import]

You should read some more info about pairs(). There is a next() method returned.
http://lua.gts-stolberg.de/en/generischFor.php [import]uid: 138389 topic_id: 31034 reply_id: 124076[/import]

okay. thank you.
I found an example that demonstates the error:

 local t = { a = 1 }  
 for k, v in pairs( t ) do  
 t.a = nil -- Remove current key from t  
 t.b = 2 -- Add a new key   
 end  

Quote: “When an event fires, you iterate over that event’s list and send the event to each of the registered functions. So if an event fires, and one of its registered functions unregisters itself, and then it registers a new function for the same event, you’ll get this error.”
-> http://www.wowinterface.com/forums/showthread.php?t=39330

so you need to make sure that the object table doesn’t change while being iterated.
[import]uid: 70635 topic_id: 31034 reply_id: 124131[/import]

You should read some more info about pairs(). There is a next() method returned.
http://lua.gts-stolberg.de/en/generischFor.php [import]uid: 138389 topic_id: 31034 reply_id: 124076[/import]

okay. thank you.
I found an example that demonstates the error:

 local t = { a = 1 }  
 for k, v in pairs( t ) do  
 t.a = nil -- Remove current key from t  
 t.b = 2 -- Add a new key   
 end  

Quote: “When an event fires, you iterate over that event’s list and send the event to each of the registered functions. So if an event fires, and one of its registered functions unregisters itself, and then it registers a new function for the same event, you’ll get this error.”
-> http://www.wowinterface.com/forums/showthread.php?t=39330

so you need to make sure that the object table doesn’t change while being iterated.
[import]uid: 70635 topic_id: 31034 reply_id: 124131[/import]