https://gyazo.com/f9c3b34a4f4997601e997c4e847d1573
Thank you in advance!
local track1 = {}
--# Add sound at position 10
track1[10] = "soundValue"
--# Add another sound at position 4
track1[4] = "anotherSound"
If each track can have multiple sounds at one position, you'll need to store a table at each position, instead of just a single value.
local tracks = {}
tracks[1] = {} --# If you don't make each sub track a new table, it'll error when you try to put a value in it.
tracks[1][4] = "sound" --# In the 1st track, but "sound" at position 4
local sparseTable = { ["bob"] = "hi" , ["jane"] = "hello" , ["SomeoneElse"] = "anotherthing" } --# Using 'pairs' on this table can return them in any order - you don't know before hand
local nonSparse = { "hi" , "hello" , "anotherthing" } --# When using the ordered-respecting 'ipairs', this table will be returned in the correct order.
No, 'ipairs' won't correctly return the first table's contense.
local tracks = {}
tracks[1] = {}
tracks[1][100] = "sound" -- adding a sound at key 100
tracks[1][50] = "sound2" -- adding a sound at key 50
#myTable returns the highest index in your table before a nil value is encountered. table.maxn(myTable) returns the highest non-nil index, full-stop, but executes slower and usually isn't needed.
function table.maxn(myTable)
local maxn = 0
for key, _ in pairs(myTable) do if type(key) == "number" and key > maxn then maxn = key end end
return maxn
end