Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you make table.insert insert the value to a specific place in the table?

Asked by 5 years ago

So I have a table where I want to insert a number into and I want it to be in the second key "[2]" but I wanted to know if it's possible.

0
tab[2] = value User#19524 175 — 5y
0
Yeah it works. But you can't use table.insert to do that  unfortunately https://gyazo.com/5910c7a1c3a2464aec58f9c8e307806e User#19524 175 — 5y
1
You actually can you table.insert to do that. table.insert(table, index, value) Impacthills 223 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

In lua you can do exactly what you want with the table.insert(t, i, v)

Example:

local t = {}

table.insert(t, 2, value) -- Where 2 is the index you are inserting the value to
0
oh nice to know User#19524 175 — 5y
0
Learning something new everyday :) Impacthills 223 — 5y
Ad

Answer this question