Hero192 Posted September 10, 2015 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
JR10 Posted September 10, 2015 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')
Hero192 Posted September 10, 2015 Author Posted September 10, 2015 about your example, so the 2nd / 3rd Messages are combined now to the table messages after using table.insert fonction?
JR10 Posted September 10, 2015 Posted September 10, 2015 Yes, so the messages table will look like this: local messages = {'First message', 'Second message', 'Third message'}
KariiiM Posted September 11, 2015 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
JR10 Posted September 11, 2015 Posted September 11, 2015 The point here is to explain what table.insert does, not keep the code short.
KariiiM Posted September 11, 2015 Posted September 11, 2015 I know you already explained so i want to show another way to use this function
JR10 Posted September 11, 2015 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'}}
KariiiM Posted September 11, 2015 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'})
JR10 Posted September 11, 2015 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.
Al3grab Posted September 11, 2015 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
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