Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Copy a Table and Make it its own independent object
Started by Keen_Ha Jun 11 2018 08:01 PM

- - - - -
1 reply to this topic
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 1 posts
  • Corona SDK


Can someone please help?


I have copied a table and would like to use the contents of the copied table as their own object. But when i do it refers back to the original object and modifies that. The contents of the tables were (display.newImage)'s (there were two of them). Can i copy the table and then have all four objects displayed at once. 



[TOPIC: post.html]

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 23,917 posts
  • Corona Staff

You will need to make four unique display objects. You can't table copy to make multiple versions.


Now for tables in general in Lua, when you do:


local table2 = table1


All you are doing is assigning the memory address of table1 to table2 (and some meta information like it being a table). You're not making a unique copy of the table.  Look at this article on helping you understand how to do a deep copy:






Also tagged with one or more of these keywords: lua