I've submitted this cartridge to the WIP section because it is not finished, it does not have sound and it starts lagging like crazy after a minute. I would appreciate it if someone could tell me a way to store a table with the bullets and remove them once they are no longer visible. I have tried using the DEL() function, but it just changes a value into nil, which bugs the code.
How are the bullets stored in a table?
This is pretty much the way they are stored:
if btn(4) then -- storing the X so it stays there add(bullets, player_x) -- storing the Y, so it can be changed add(bullets, 100) end |
And this is how the table is read:
for i=1, #bullets do if i % 2 == 0 then -- change the y so that they go up bullets[i-1] -= 2 end end |
So I really need help finding a better way to store them and removing the unnecessary bullets.



You should store tables (e.g. struct or classes in other languages) and update attributes.
(never checked, but not sure you can remove values - as opposed to references - from a lua array)
In your case, something like:
if btn(4) then -- storing the X so it stays there -- storing the Y, so it can be changed add(bullets, {x=player_x, y=100}) end ... for i=1, #bullets do local b=bullets[i] if b.y<200 then b.y-=2 else del(bullets,b) end end |
[Please log in to post a comment]