Unpack multiple tables

Hey guys!
I ran into a big problem…
look at this:

tab1 = {“test”,“22”}
tab2 = {“test2”,“bla”}


Output is “testtest2bla”

so the second value and up of the first table arent unpacked.

You can’t.

The alternative is to move all of your values in to a single table and call unpack on that.


Nope, because of Colors

You can do something like this:

local oldUnpack = unpack
function unpack( ... )
    local t = {}
    for _, v1 in pairs( {...} ) do
        for _, v2 in pairs( v1 ) do
            t[ #t + 1 ] = v2
    return oldUnpack( t )

print( unpack( tab1, tab2 ) )

All you have to do is concatenate [ADD] the tables or if they are literally defined just declare them as one. The way chat.AddText works is, it prints with the last defined color in a sequential table so…

local chatText = {Color(255,0,0), “Red”, “also red”, Color(0,0,0), “Now it prints black”}

// this is the same thing
local part1 = {Color(255,0,0), “Red”, “also red”}
local part2 = {Color(0,0,0), “Now it prints black”}
chat.AddText(unpack(table.Add(part1, part2)))

It’s possible that table.Add will not insert values from the source table to the destination table in the correct order.

So loop through and insert each index?

for k,v in ipairs(part2) do
table.insert(part1, v)

Assuming the table you want to add is numerically indexed.

silly idea but maybe
local table = {
[ 1 ] = { color = Color( 255, 255, 255, 255 ), text = “ow hellow there!” },
[ 2 ] = { color = Color( 255, 0, 0, 255 ), text = “You just changed color!” },
chat.AddText( table[ 1 ].color, table[ 1 ].text, table[ 2 ].color, table[ 2 ].text )


Now you have everything you need in 1 table and you can use it like above.