Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

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

- - - - -
2 replies to this topic
lua
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Keen_Ha

[GLOBAL: userInfoPane.html]
Keen_Ha
  • Observer

  • 1 posts
  • Corona SDK

Hi,

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. 

 

Thx 



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,714 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:

 

http://lua-users.org/wiki/CopyTable

 

Rob



[TOPIC: post.html]
#3

carloscosta

[GLOBAL: userInfoPane.html]
carloscosta
  • Contributor

  • 595 posts
  • Corona SDK

https://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: lua