Unpacking Colors

What is a good way to unpack a table and print it with _G.MsgC?
The current issue is that the color is turned into a table and will just print the table.

The issue:


Just wondering if this has anything to do with it:
Unpack the table into separate variables and then put those variables into MsgC with proper concatenation. If concatenation isn’t the issue, I’d look at the syntax definition for MsgC:

MsgC( color, str, ... )

and say that you’re just printing the Color object instead of actually printing a coloured text output, because the returned stuff from unpack isn’t returning “Color rgb(…), “mystring”, …”

I don’t have Garry’s Mod 13, so I’m just going off of what seems wrong.

The issue is that unpack is returning a table rather than a color object, strange that it works for the first index.

cols = Color(255, 255, 255, 255)PrintTable(cols)


a        =        255
b        =        255
g        =        255
r        =        255

if it’s any help.

Yes I know, how would I get about turning the table into a color?

Would this work?

local stuff(…)
local arguments = {…};

 for k, v in pairs(arguments) do
      if (type(v) == "table") then
           v = Color(v.r, v.g, v.g, v.a);



Yeah, if MsgC() doesn’t automatically print newlines and works on the same sort of stacking that regular Msg works with this should work (pretty similar to your way):

function is_color(colorarr)
–Small thing to check for a color table
local flag = false
if type(colorarr) ~= “table” then return flag end
for k, _ in pairs(colorarr) do
if k == “r” or k == “g” or k == “b” or k == “a” then flag = true
else flag = false end
return flag


Couldn’t test the actual script, but if it follows what I asked about it, this is how I’d do it.

[editline]3rd May 2012[/editline]

Yeah, nevermind with the second part of that code. MsgC doesn’t stack like that. Sorry, don’t know what to do here. Hope someone else knows how to do this :frowning:

You cannot unpack tables that have no integral indexes or malformed indexes like this:


nevermind this but.

MsgC does only support 1 color and 1 text afaik.


function isColor(tbl) return tbl.r and tbl.g and tbl.b and tbl.a end