Garry's Mod Wiki

table.move

  table table.move( table sourceTbl, number from, number to, number dest, table destTbl = sourceTbl )

Description

Moves elements from one part of a table to another part a given table. This is similar to assigning elements from the source table to the destination table in multiple assignments.

Arguments

1 table sourceTbl
The source table from which the elements are to be moved.
2 number from
The start index of the source range from which the elements are to be moved.
3 number to
The end index of the source range until which the elements are to be moved.
4 number dest
The index within the destination table where the moved elements should be inserted.
5 table destTbl = sourceTbl
The destination table to which the elements are to be moved. By default, this is the same as the source table.

Returns

1 table
The modified destination table.

Example

Example of the this can be used.

local source = { "a", "b", "c", "d", "e" } local dest = { "f", "g", "h", "i", "j" } table.move( source, 3, 5, 1, dest ) PrintTable( source ) print( "\n" ) PrintTable( dest )
Output:
1 = a 2 = b 3 = c 4 = d 5 = e 1 = c 2 = d 3 = e 4 = i 5 = j