How to insert table so table destroy when scene change

hey guys i ran into a little problem, i am spawning some objects on screen but when i try to rest the game scene from the win scene the objects i am try to spawn doesn’t rest them. i believe this  problem pop up because i am not inserting the objects into a group so when the scene change the objects/ table destroy himself.  also the coinsTable is in my create scene, try to insert the table by doing this 

coinsTable = { "awards/coin01", "awards/coin02", "awards/coin03","awards/coin04"} coins = {} table.insert(coinsTable, coins);

but i wind up with an error "attempt to concatenate field ?  " (a table value) the line the error occurred is

coins [#coins + 1] = display.newImage( coinsTable[ranNum]..".png" ) 

 this function below spawn my coins   

function spawnCoins() ranNum = math.random(#coinsTable ) coins [#coins + 1] = display.newImage( coinsTable[ranNum]..".png" ) coins[#coins].x = math.random(-10, 300); coins[#coins].y = -40; coins[#coins].id = coinsNum coins[#coins].name = "coins" physics.addBody( coins[#coins], "dynamic", { friction =1, bounce =0, density=0 } ) transition.to( coins[#coins], {time = math.random(2000, 8000), x = math.random(100, 300) , y = 600, onComplete = remove}); coins[#coins]:addEventListener("touch", touchCoins) -- touch coins[#coins].isFixedRotation = true end --total\_enemy = 10 timer8 =timer.performWithDelay( 1000, spawnCoins, 0 ) 

can someone please help my 

thanks :slight_smile: you help will be greatly appreciated  

Why are you doing the table.insert()?  If I read that right, you’re inserting an empty table into your table of filenames.

Also where is this code located in your scene file?
 

Rob

the coinsTable is in the create scene and the function that create the coins is outside the create scene. also i am not sure but would it go like this  

 coins.insert(coinsTable, coins);     

thanks :) 

But why are you doing it at all?   coins is a table of your display objects.  coinsTable is your list of filenames.  I don’t see why you need to do this.  If it does what you think, then you end up with objects in coins that are not display.newImageRects() and you’re trying to manipulate them like display objects.

Rob

thanks for letting me know that so when i am using table i don’t have to remove them when i am done with them?

Well it depends on a lot of factors.  In your case of your table of file names, no you don’t need to empty it.  It’s almost like constants.  Depending on how you’re doing your scenes, it may get unloaded when the scene is removed.  Generally a table like that is so little data you don’t have to worry about it.  

Now your table of coins, each entry contains a display object that those display objects eat up large chunks of memory.  Those need to be removed and nil’ed when you are done with them.

Be aware if you nil the entry in the table:

display.remove(coins[4])

coins[4] = nil

#coins will equal 3 even though you may 100 of them.  There is a function table.maxn(coins) will return the true length of the table.    Using #coins (and #coins+1) works as long as there are no nil members.

i understand thanks rob i might know how to fix my problem now thanks for your help  :slight_smile:

I want to implement videochat option in ma App…?..plz help me…

Why are you doing the table.insert()?  If I read that right, you’re inserting an empty table into your table of filenames.

Also where is this code located in your scene file?
 

Rob

the coinsTable is in the create scene and the function that create the coins is outside the create scene. also i am not sure but would it go like this  

 coins.insert(coinsTable, coins);     

thanks :) 

But why are you doing it at all?   coins is a table of your display objects.  coinsTable is your list of filenames.  I don’t see why you need to do this.  If it does what you think, then you end up with objects in coins that are not display.newImageRects() and you’re trying to manipulate them like display objects.

Rob

thanks for letting me know that so when i am using table i don’t have to remove them when i am done with them?

Well it depends on a lot of factors.  In your case of your table of file names, no you don’t need to empty it.  It’s almost like constants.  Depending on how you’re doing your scenes, it may get unloaded when the scene is removed.  Generally a table like that is so little data you don’t have to worry about it.  

Now your table of coins, each entry contains a display object that those display objects eat up large chunks of memory.  Those need to be removed and nil’ed when you are done with them.

Be aware if you nil the entry in the table:

display.remove(coins[4])

coins[4] = nil

#coins will equal 3 even though you may 100 of them.  There is a function table.maxn(coins) will return the true length of the table.    Using #coins (and #coins+1) works as long as there are no nil members.

i understand thanks rob i might know how to fix my problem now thanks for your help  :slight_smile:

I want to implement videochat option in ma App…?..plz help me…