Keeping track of bullet colliders

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
M_Bison
Prole
Posts: 2
Joined: Tue Aug 26, 2014 1:13 pm

Keeping track of bullet colliders

Post by M_Bison »

I'm creating a top-downshooter and I want to keep track of all my bullets in a table, so I can iterate through them so I can later delete them ,and also move them during the update loop.

I created a table

Code: Select all

bulletsCollider = {}
tried

Code: Select all

 local num = #bulletsCollider
 bulletsCollider[num+1] = HC:addCircle(playerX,playerY,bulletRadius)
and

Code: Select all

table.insert(bulletsCollider,HC:addCircle(playerX,playerY,bulletRadius))

-- also tried

table.insert(bulletsCollider,Collider:addCircle(playerX,playerY,bulletRadius))
during my bullet creation function, but I get errors. (attempt to call method 'addCircle' (a nil value) )

Other relevant snippet of code

Code: Select all

HC = require 'hardoncollider'

function love.load() -- Initialized once

Collider = HC(100, on_collide) -- Hardon Collider init
User avatar
artofwork
Citizen
Posts: 91
Joined: Mon Sep 15, 2014 1:17 am
Location: East Coast USA

Re: Keeping track of bullet colliders

Post by artofwork »

If you get errors when trying to update a table, try a conditional statement, since HC:addCircle() returns a value you can check if its holding a valid value and then apply it to a table eliminating the error.

Code: Select all

if HC:addCircle(playerX, playerY, bulletRadius) ~= nil then
     table.insert(bulletsCollider, HC:addCircle(playerX, playerY, bulletRadius))
else
     -- else code here or just use the if the statement
end

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 6 guests