Search code examples
lualua-table

Displaying Lua tables to console by concatenating to string


I was wondering whether it is possible to display tables in the console. Something like:

player[1] = {}
player[1].Name   = { "Comp_uter15776", "maciozo" }

InputConsole("msg Player names are: " .. player[1].Name)

However, this is obviously wrong as I receive the error about it not being able to concatenate a table value. Is there a workaround for this?

Much thanks in advance!


Solution

  • To turn an array-like table into a string, use table.concat:

    InputConsole("msg Player names are: " .. table.concat(player[1].Name, " "))
    

    The second argument is the string placed between each element; it defaults to "".