Jump to content

table.insert QUESTION


Hero192

Recommended Posts

Posted

It inserts a new item in the table.

local messages = {'First message'} 
table.insert(messages, 'Second message') 
table.insert(messages, 'Third message') 

Posted

Yes, so the messages table will look like this:

local messages = {'First message', 'Second message', 'Third message'} 

Posted (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 by Guest
Posted

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'}} 

Posted

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'}) 

Posted
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 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...