it works perfectly, thanks xxxfanta, you're great
i have a trouble with your code
when i'm trying to remove objects and then spawn them again i get this error:
attempt to perform arithmetic on local "bx" (a nil value)
what's i'm supposed to do? is there a best way to remove objects so this problem would not occur?
Make sure to cancel the timer first!
timer:cancel(spawnTimer)
And don't forget removing objects "reversed"
i.e.:
1
2
3
4
| for i=#mySpawnedObjects,1,-1 do
mySpawnedObjects[i]:removeSelf();
mySpawnedObjects[i] = nil;
end |
glad for help, but alrady solved my problems)
by the way, why use reversed loop? is there any practical difference to simple loop?
Sure.
When you remove the objects from 1 to #mySpawnedObjects, you'll get an error at half the way.
Why? Because those indices don't exist anymore!
If you have a table with t[1], t[2], ... t[5] and remove the first one, everyone will move in their position (since LUA tables don't want to have "holes").
Therefor after deleting 3 of those, he can't find t[4], since there are only t[1] and t[2] left.
Hope that makes sense
that makes sense, thanks
though for removing all things at once i find its ok to use simple loop
Well you still should use a reversed one, otherwise you will run into errors! (since you can't delete everything at once)