[08 May 2007] Copy table element

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
User avatar
lazi
Posts: 646
Joined: Thu Feb 24, 2011 11:08 pm

[08 May 2007] Copy table element

Post by lazi »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 08 May 2007 14:24:45 +0100

Hi!

I would like to copy an element of a table array to another element like this:

Code: Select all

dim but[10]

but[1] = { off=1,
        on= 2,
        x=  100,
        y=  100,
        w=  59,
        h=  46,
        nr= 1
      }

but[2]=but[1]    
but[2] will be just a reference to but[1] however I need a copy of but[1].

Is there a way to copy the contents of the table to another variable?
User avatar
airsoftsoftwair
Posts: 5834
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[11 May 2007] Re: Copy table element

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Fri, 11 May 2007 11:44:51 +0200
Hi!

I would like to copy an element of a table array to another element like this:

Code: Select all

dim but[10]

but[1] = { off=1,
       on= 2,
       x=  100,
       y=  100,
       w=  59,
       h=  46,
       nr= 1
     }

but[2]=but[1]    
but[2] will be just a reference to but[1] however I need a copy of but[1].

Is there a way to copy the contents of the table to another variable?
Hmm... good question. I would go for a manual copy, i.e.

Code: Select all

but[2].off = but[1].off
but[2].on = but[1].on
but[2].x = but[1].x
etc.

There's probably no other way to do a full copy.
Locked