Recommended Posts

local table = {
	{"1", "2", "3", "4"},
}

function asdasdsdasdd()
table.insert(table,"5","6","7","8")
end

What wrong? No errors and warnings in debugscript 3...

Share this post


Link to post

Because table.insert inserts only 1 value to table.

In your case you should use for loop and call table.insert per iteration.

Please read Lua docs:

 

Edited by Kenix
  • Like 1

Share this post


Link to post
2 hours ago, Kenix said:

Because table.insert inserts only 1 value to table.

In your case you should use for loop and call table.insert per iteration.

Please read Lua docs:

 

Ah, can you show me a example, please?

Share this post


Link to post
local table = {
    {"1", "2", "3", "4"},
}

function startInsert()

for k=5,8 do
table.insert(table,tostring(k))

end
end

startInsert()

 

  • Like 1

Share this post


Link to post

try your new code here

https://www.Lua.org/cgi-bin/demo


 

table = {"1","2","3"}


function insertt()

table[#table+1]="4"
table[#table+1]="5"
table[#table+1]="6"
table[#table+1]="hello"
table[#table+1]=7
table[#table+1]=8

for k,v in pairs(table) do
print(v)
end

end


insertt()

 

Share this post


Link to post

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.