Quick Question. Generic for not updating all values.
Posted: Wed Oct 06, 2010 6:45 pm
I've been struggling with this for too long! There has to be a better solution. I'm having problems looping through a table of objects.
let's say I create a rock in my rocks table.
then I want to update the objects ... in love update
this works for moving the rocks and updating the instances.
But I start to run into problems when I want to hit multiple rocks. For some reason the following code will return true only on the last index of the rocks table.
Does anyone know what would cause this? I've been banging my head against it for a little while. Leads, tips, links are all accepted and appreciated.
let's say I create a rock in my rocks table.
Code: Select all
function love.keypressed( key )
if key == " " then
--newRock(x,y,weight)
table.insert(rocks,newRock(math.abs(love.mouse.getX()), -50,1))
end
end
Code: Select all
function update(dt)
for n, b in ipairs(rocks) do
b:update(dt)
end
end
But I start to run into problems when I want to hit multiple rocks. For some reason the following code will return true only on the last index of the rocks table.
Code: Select all
-- xan is the player
-- some is a debug var so we can see if it's working.
for i,v in ipairs(rocks) do
if checkHit(xan,v) then
some = "you're hitting!"
else
some = "not hitting any"
end
end