Help removing display objects

Hey all. I’m really sorry to be asking such a relatively simple question, but my brain seems to have gone awol and I can’t figure this out.
I have a two level parallax scrolling landscape with scenery that is generated at random and stored in a table. What (for some reason) I’m having difficulty with is removing the items from the table once they have left the screen. Please help before I pull all of my hair out :frowning:

Cheers
Chris
[import]uid: 7841 topic_id: 35249 reply_id: 335249[/import]

I would need to see some code to get a better idea of the structure. But I’d be more than happy to help if I can.

Cheers. [import]uid: 202223 topic_id: 35249 reply_id: 140109[/import]

Just remember when you remove stuff from a table, you need to remove in reverse order or else re-sort…

-- proper reverse order removal for i = #tablename, 1, -1 do --remove row end

[import]uid: 41884 topic_id: 35249 reply_id: 140111[/import]

If you want to just remove -one- of these items from the table (which I assume you’ve populated simply by the Lua object IDs), and you don’t know the position of the object within that table, you need to do a “by name” removal. I use the following… of course, there’s probably a more efficient way in Lua, but this works for me and I’ll go with the “if it ain’t broke, don’t fix it” stand here. :slight_smile:

local function removeID( tableID, name )  
 for i=1,#tableID do  
 local v = tableID[i] ; if ( v and v == name ) then table.remove( tableID,i ) ; break end ; v = nil  
 end  
end  
--remove one of the items  
removeID( yourHoldingTable, object ) --'object' being the Lua ID 'table'  

Brent [import]uid: 200026 topic_id: 35249 reply_id: 140123[/import]

Corrected… and I know there is no such call in Lua. I simply had “table.remove” assigned to a local variable “table_remove” higher up, since I use it in several places. I forgot to change that instance when I copied and pasted this bit from my code. [import]uid: 200026 topic_id: 35249 reply_id: 140170[/import]

DOH! table.remove! That’s the badger. I was halfway there but I was using scenery.remove (scenery being the name of my table), and I couldn’t understand why it wasn’t working. The annoying thing is that I’ve used it in the past but just couldn’t quite remember it.
Many many thanks guys! [import]uid: 7841 topic_id: 35249 reply_id: 140247[/import]

I would need to see some code to get a better idea of the structure. But I’d be more than happy to help if I can.

Cheers. [import]uid: 202223 topic_id: 35249 reply_id: 140109[/import]

Just remember when you remove stuff from a table, you need to remove in reverse order or else re-sort…

-- proper reverse order removal for i = #tablename, 1, -1 do --remove row end

[import]uid: 41884 topic_id: 35249 reply_id: 140111[/import]

If you want to just remove -one- of these items from the table (which I assume you’ve populated simply by the Lua object IDs), and you don’t know the position of the object within that table, you need to do a “by name” removal. I use the following… of course, there’s probably a more efficient way in Lua, but this works for me and I’ll go with the “if it ain’t broke, don’t fix it” stand here. :slight_smile:

local function removeID( tableID, name )  
 for i=1,#tableID do  
 local v = tableID[i] ; if ( v and v == name ) then table.remove( tableID,i ) ; break end ; v = nil  
 end  
end  
--remove one of the items  
removeID( yourHoldingTable, object ) --'object' being the Lua ID 'table'  

Brent [import]uid: 200026 topic_id: 35249 reply_id: 140123[/import]

Corrected… and I know there is no such call in Lua. I simply had “table.remove” assigned to a local variable “table_remove” higher up, since I use it in several places. I forgot to change that instance when I copied and pasted this bit from my code. [import]uid: 200026 topic_id: 35249 reply_id: 140170[/import]

DOH! table.remove! That’s the badger. I was halfway there but I was using scenery.remove (scenery being the name of my table), and I couldn’t understand why it wasn’t working. The annoying thing is that I’ve used it in the past but just couldn’t quite remember it.
Many many thanks guys! [import]uid: 7841 topic_id: 35249 reply_id: 140247[/import]