Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过连接到字符串将Lua表显示到控制台_Lua_Lua Table - Fatal编程技术网

通过连接到字符串将Lua表显示到控制台

通过连接到字符串将Lua表显示到控制台,lua,lua-table,Lua,Lua Table,我想知道是否可以在控制台中显示表格。比如: player[1] = {} player[1].Name = { "Comp_uter15776", "maciozo" } InputConsole("msg Player names are: " .. player[1].Name) 但是,这显然是错误的,因为我收到的错误是无法连接表值。有解决办法吗 非常感谢 要将类似数组的表格转换为字符串,请使用table.concat: InputConsole("msg Player names

我想知道是否可以在控制台中显示表格。比如:

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

InputConsole("msg Player names are: " .. player[1].Name)
但是,这显然是错误的,因为我收到的错误是无法连接表值。有解决办法吗


非常感谢

要将类似数组的表格转换为字符串,请使用
table.concat

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

第二个参数是放置在每个元素之间的字符串;它默认为

,以使您的生活更轻松。。。我还建议在内部表中命名元素。当您需要获取表中对某些目的有意义的特定值时,这使得上面的代码更易于阅读

-- this will return a new instance of a 'player' table each time you call it.  
-- if you need to add or remove attributes, you only need to do it in one place.
function getPlayerTable()
    return {FirstName = "", LastName = ""}
end

local players = {}

local player = getPlayerTable()
player.FirstName = "Comp_uter15776"
player.LastName = "maciozo"
table.insert(players, player)

... more code to add players ...

local specific_player = players[1]
local specific_playerName = specific_player.FirstName.. 
                            " ".. specific_player.LastName
InputConsole("msg Some message ".. specific_playerName)

非常感谢你!正是我需要的:)