I’m working on a project and I’d like to add a few objects to a table/array. I created my items, table, etc
local box = display.newImage("box.png")
local board = display.newImage("board.png")
local array = {}
-- insert items into array, this is typically done programatically
-- so they are not already added at creation of table
table.insert(array, box)
table.insert(array, board)
local index = table.indexOf(array, box) -- this should return 1 right?
print("Index: " .. index)
Instead I get: attempt to call field ‘indexOf’ (a nil value)
So I thought it was returning a nil value so that was the issue. so I tried:
local index = table.indexOf(array, box)
if (index == nil) then
print("It's nil")
end
still same result (Runtime Error)
I’m really wanting to remove items from my array. I tried searching through the array and removing the item. This works, but the array wont re-order the index value. So it thinks index 1 is still there but instead I later learned it leaves a “hole”. So I’d like to do this:
table.remove(array, table.indexOf(array, box))
EDIT: Also, shouldn’t this work just fine as I see in the docs:
local tab = {1, 2, 3, 4, 5}
print("Index is: " .. table.indexOf(tab, 4))
Can anyone shed some light on this one?
Thanks for any and all help,
-d [import]uid: 27681 topic_id: 10991 reply_id: 310991[/import]