@Majormorgan let’s represent your bulletclass by Bullet(‘your args would go here’)
to add a bullet to your table, you’d have to do
-- this adds a Bullet() in the bullets table
table.insert(bullets, Bullet() )
to draw this, you’d use iPairs or pairs (I never know which one it is), these loop over a table for you, but since you want to understand it all, here’s the manual looping
-- table index starts at 1
-- table index stops at the number of elements inside the table
for i = 1, #bullets do
bullets[i]:draw()
end
-- since every element inside the table, is actually an instance of a class, you can draw the instance like this
for the removal of an instance, let’s say there’s a var inside of your Bullet() class that’s a boolean and contains weather or not the bullet is on screen
the checking of this could be done inside of the drawing loop
-- we'll create a temp table to store the indices of all bullets that aren't on screen
local tempTable = {}
for i = 1, #bullets do
bullets[i]:draw()
if bullets[i].onScreen == false then
table.insert(tempTable, i)
end
end
-- when the loop is done, we now have all the indices of the bullets
-- which may be removed, to remove them, we'll go through a backwards
-- loop, because if we'd do a normal loop, we'd for example delete index
-- 1, but then everything else gets shoved up 1 place and you'll remove
-- wrong indices
-- starting at the last index of the table, to index 1, reducing the value with -1 every loop
for i = #tempTable, 1, -1 do
-- we now remove a bullet in the bullets table
-- the index of the bullet we remove, is stored inside of the tempTable
table.remove(bullets, tempTable[i])
end
I hope this helped you a bit, but I’m sure others will explain it way better
edited because of the corrections @yojimbo2000 made (thanks for that)