Remove items in table error.

I have game and when you get your special, all the crates on the field destroy.  As I hit the first crate, all the crates play the “destroy” animation.  As I keep playing and do it a second time it says… "attempt to call method ‘setSequence’ (a nil value).

here is the code…

function special(event) for i=1,#objectsArray do if objectsArray[i] ~= nil and objectsArray[i].name == "crate" then local child = objectsArray[i].item if child ~= nil then child:setSequence("destroy") child:play() child.isBodyActive = false child = nil end end end end

just in case, the setSequence is stored here…

local objectProperties = { ------------------------------------------------------------------- crate = {--START OF CRATE id = "crate", xp = 0, stackable = "no", damage = 50, category = "normal", score = 50, sprite = { imageSheet = "crateImageSheet.png", imageSheetInfo = "crateImageSheet", sequenceData = { default = { start = "crate\_01", count = 1, loopCount= 1 }, destroy = { start = "crate\_01", count = 7, time = 450, loopCount = 1 } } },

I would like for all of the crates to be destroyed and erased out of the table, however I still need to access the table again without getting nils.

Hi @anthonyfrank,

Before and after you loop through “objectsArray”, between lines 1-2 and 12-13 in your first example code bit here, insert a test print() line to check the number of objects within the table, i.e.

[lua]

print(#objectsArray)

[/lua]

Does it match what you expect? Meaning, does the new value (after) reflect the number of crates destroyed compared to the value before?

Brent

Hi @anthonyfrank,

Before and after you loop through “objectsArray”, between lines 1-2 and 12-13 in your first example code bit here, insert a test print() line to check the number of objects within the table, i.e.

[lua]

print(#objectsArray)

[/lua]

Does it match what you expect? Meaning, does the new value (after) reflect the number of crates destroyed compared to the value before?

Brent