我想知道是否可以在控制台中显示表格,类似于:
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)