Overkillz Posted September 27, 2017 Share Posted September 27, 2017 Hello dear guys. Im getting mad trying to solve this simple question. Well, I have a table like the following one and it has a value which is a boolean (The last one). Im trying to use table.concat to output them, however, it doesn't work. (I won't use quote characters inside the table. ) They can be used on output or whatever inside the code loop to output them local tablaPrueba = { {"object1","valor1","valor1","valor1"}, {"object2","valor2","valor2","valor2"}, {"object3","valor3","valor3","valor3"}, {"object4","valor4","valor4","valor4"}, {"object5","valor5","valor5","valor5"}, {"object6","valor6","valor6","valor6"}, {"object7","valor7","valor7",true}, } for i,objects in ipairs(tablaPrueba) do outputChatBox("{"..table.concat(objects,", ").."}")]] end Thanks for reading. Regards. Link to comment
pa3ck Posted September 27, 2017 Share Posted September 27, 2017 I don't think it will be as simple as using table.concat.. You'd probably need to implement your own way of string, boolean and number concatenation eg. looping thru the data. local tablaPrueba = { {"object1","valor1","valor1","valor1"}, {"object2","valor2","valor2","valor2"}, {"object3","valor3","valor3","valor3"}, {"object4","valor4","valor4","valor4"}, {"object5","valor5","valor5","valor5"}, {"object6","valor6","valor6","valor6"}, {"object7","valor7","valor7",true}, } local myStr for k, v in ipairs(tablaPrueba) do local myStr = "{" for x, y in ipairs(v) do if type(y) == "string" then myStr = myStr .. '"'..y..'", ' elseif type(y) == "number" then myStr = myStr .. y..', ' elseif type(y) == "boolean" then myStr = myStr .. tostring(y) .. ", " end end myStr = myStr:sub(1, -3) .. "}," outputChatBox(myStr) end But using toJSON and fromJSON would be your best option. 1 Link to comment
Overkillz Posted September 27, 2017 Author Share Posted September 27, 2017 Thanks, I didnt remember toJSON and fromJSON. It has helped me a lot. Thanks for it man. Best regards. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now