The behavior of next is undefined if, during the traversal, you assign any value to a non-existent field in the table. You may however modify existing fields. In particular, you may clear existing fields.
Problem with drawing moving sprites.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Problem with drawing moving sprites.
Ipairs is unsafe with either adding or removing, but next (and thus pairs) is safe when removing, but not adding. The relevant line from the manual:
Re: Problem with drawing moving sprites.
That is helpful!bartbes wrote:Ipairs is unsafe with either adding or removing, but next (and thus pairs) is safe when removing, but not adding. The relevant line from the manual:The behavior of next is undefined if, during the traversal, you assign any value to a non-existent field in the table. You may however modify existing fields. In particular, you may clear existing fields.
Regarding updating objects the same frame they were added into the vector, how about this:
Code: Select all
local max = #EntityManager.objects
local index = 1
while index <= max do
local e = EntityManager.objects[index]
e:update(dt)
if not e:isAlive() then
table.remove(EntityManager.objects, index)
else
index = index + 1
end
max = #EntityManager.objects
end
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], ChocolateLoxtl and 6 guests