Hero192 Posted September 10, 2015 Share Posted September 10, 2015 Hey guys, can i know why we use table.insert ? don't recommand for me the lua website because it's hard to understand and please give me example Link to comment
JR10 Posted September 10, 2015 Share Posted September 10, 2015 It inserts a new item in the table. local messages = {'First message'} table.insert(messages, 'Second message') table.insert(messages, 'Third message') Link to comment
Hero192 Posted September 10, 2015 Author Share Posted September 10, 2015 about your example, so the 2nd / 3rd Messages are combined now to the table messages after using table.insert fonction? Link to comment
JR10 Posted September 10, 2015 Share Posted September 10, 2015 Yes, so the messages table will look like this: local messages = {'First message', 'Second message', 'Third message'} Link to comment
KariiiM Posted September 11, 2015 Share Posted September 11, 2015 (edited) It inserts a new item in the table. local messages = {'First message'} table.insert(messages, 'Second message') table.insert(messages, 'Third message') Or this way storing all datas in one function to avoid repeating local messages = {'First message'} table.insert(messages, {'Second message','Third message'}) Edited September 11, 2015 by Guest Link to comment
JR10 Posted September 11, 2015 Share Posted September 11, 2015 The point here is to explain what table.insert does, not keep the code short. Link to comment
KariiiM Posted September 11, 2015 Share Posted September 11, 2015 I know you already explained so i want to show another way to use this function Link to comment
JR10 Posted September 11, 2015 Share Posted September 11, 2015 Well, it's incorrect. This way you are inserting a table inside the table, not inserting two items. The messages table will look like this: local messages = {'First message', {'Second message', 'Third message'}} Link to comment
KariiiM Posted September 11, 2015 Share Posted September 11, 2015 Ah you're right,i didn't take attention,so my way works only if the table is empty like that local messages = {} table.insert(messages, {'First message','Second message','Third message'}) Link to comment
JR10 Posted September 11, 2015 Share Posted September 11, 2015 Not even when it's empty, it will be the same without 'First message', that is, a table inside a table. Link to comment
Al3grab Posted September 11, 2015 Share Posted September 11, 2015 It inserts a new item in the table. local messages = {'First message'} table.insert(messages, 'Second message') table.insert(messages, 'Third message') Or this way storing all datas in one function to avoid repeating local messages = {'First message'} table.insert(messages, {'Second message','Third message'}) meh, that would be local messages = {'First message'} for u,sk in ipairs ( {'Second message','Third message'} ) do table.insert(messages,sk) end 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