Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can anyone help me with this table bug?

Asked by
crut24 50
8 years ago
Edited 8 years ago
local DaTable = {TimeString = "19/6/2016",EnemyString = "Hi" ,OfficialBool =true,WinBool = true}
local NewTable = {}
table.insert(NewTable,1,DaTable) 
print(table.concat(NewTable[1], " "))

What it prints out is "" <--- Equal to nil How do i fix that?

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago
Edited 8 years ago

Take a look at the wiki explanation for table.concat:

"Given an array where all elements are strings or numbers..."

DaTable doesn't fit either of those requirements. It's not an array, and it has both booleans and strings. That's why it doesn't work with table.concat. Other than that your code is fine.


You could write your own table.concat function if you wanted to:

function concatenate(table)
    local str = ""
    for key, value in pairs(table) do
        str = str .. " " .. tostring(value)
    end
    return str
end
0
When i do print(DaTable[1]) it prints out nil crut24 50 — 8y
0
DaTable[1] IS nil. It's a dictionary, so it doesn't have numbers for keys. You have to use the keys you gave it: DaTable["TimeString"] or, alternatively, DaTable.TimeString Perci1 4988 — 8y
Ad

Answer this question