What if I can’t change the dictionary format?
Im sorry if im being difficult here but I’m creating a animation loop system, I require table formats to not be changed in the way your suggesting.
EDIT: It would be even better if I can somehow convert a dictionary into this format
Let’s sort the dictionary by getting all the keys and sorting those, then using this new sorted table to get the values of those keys.
local example = {
[0] = CFrame.new(0,0,0),
[0.2] = CFrame.new(0,0,1),
[1] = CFrame.new(1,0,0),
[1.5] = CFrame.new(0,1,0),
[2] = CFrame.new(1,1,1),
}
print(example) -- the order is all weird!
local function SortDictionary(dictionary)
local new = {}
for key, _ in pairs(dictionary) do
table.insert(new, key)
end
table.sort(new)
local final = {}
for key, value in pairs(new) do
final[key] = {value, dictionary[value]}
end
return final
end
print(SortDictionary(example)) --[[ the order is how i organized it earlier, so:
{
[1] = ▼ {
[1] = 0,
[2] = 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1
},
[2] = ▼ {
[1] = 0.2,
[2] = 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1
},
[3] = ▼ {
[1] = 1,
[2] = 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1
},
[4] = ▼ {
[1] = 1.5,
[2] = 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1
},
[5] = ▼ {
[1] = 2,
[2] = 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1
}