Piorun Posted June 28, 2011 Share Posted June 28, 2011 I have a question - why this code doesn't works? newTable = { "1st value", "2nd value" } addCommandHandler("showmetable", getRootElement(), function() for i,v in ipairs(newTable) do outputChatBox(tostring(newTable[i])) end end) ??? Link to comment
Subtixx Posted June 28, 2011 Share Posted June 28, 2011 show the error. EDIT: i think this is correct: newTable = { "1st value", "2nd value" } addCommandHandler("showmetable", getRootElement(), function() for i,v in ipairs(newTable) do outputChatBox(tostring(v)) end end) Link to comment
Wojak Posted June 28, 2011 Share Posted June 28, 2011 i tested the code here (with a little edition): http://www.lua.org/cgi-bin/demo and it works fine: newTable = { "1st value", "2nd value" } -- loop from your code works fine (print instead of outputChatBox to run it in demo) for i,v in ipairs(newTable) do print(tostring(newTable[i])) end --this also works, I think its better for i,v in ipairs(newTable) do print(v) end Link to comment
Piorun Posted June 28, 2011 Author Share Posted June 28, 2011 newTable = { "1st value", "2nd value" } addCommandHandler("showmetable", getRootElement(), function() for i,v in ipairs(newTable) do outputChatBox(v) end end) I edited my code and i still have an error. Bad argument in outputChatBox Link to comment
Piorun Posted June 28, 2011 Author Share Posted June 28, 2011 ah .. i've got an error not in outputChatBox but in addCommandHandler. I fix it but thanks a lot 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