Hey guys!
I ran into a big problem..
look at this:
tab1 = {"test","22"}
tab2 = {"test2","bla"}
chat.AddText(unpack(tab1),unpack(tab2))
Output is "testtest2bla"
so the second value and up of the first table arent unpacked.
Halp?
You can't.
The alternative is to move all of your values in to a single table and call unpack on that.
table.concat?
[QUOTE=Exho;46310616]table.concat?[/QUOTE]
Nope, because of Colors
You can do something like this:
[code]
local oldUnpack = unpack
function unpack( ... )
local t = {}
for _, v1 in pairs( {...} ) do
for _, v2 in pairs( v1 ) do
t[ #t + 1 ] = v2
end
end
return oldUnpack( t )
end
print( unpack( tab1, tab2 ) )
[/code]
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...
[lua]
local chatText = {Color(255,0,0), "Red", "also red", Color(0,0,0), "Now it prints black"}
chat.AddText(unpack(chatText))
// 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)))
[/lua]
[QUOTE=Ludicium;46323299]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...
[lua]
local chatText = {Color(255,0,0), "Red", "also red", Color(0,0,0), "Now it prints black"}
chat.AddText(unpack(chatText))
// 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)))
[/lua][/QUOTE]
It's possible that table.Add will not insert values from the source table to the destination table in the correct order.
[QUOTE=Willox;46323523]It's possible that table.Add will not insert values from the source table to the destination table in the correct order.[/QUOTE]
So loop through and insert each index?
[lua]
for k,v in ipairs(part2) do
table.insert(part1, v)
end
[/lua]
Assuming the table you want to add is numerically indexed.
silly idea but maybe
[lua]
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 )
[/lua]
Now you have everything you need in 1 table and you can use it like above.
Sorry, you need to Log In to post a reply to this thread.