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

How do I use table.insert on a dictionary?

Asked by
Trew86 175
6 years ago
Edited 6 years ago
local preferredPaths = {}

local function convert(route)
    local notPreferred = route:FindFirstChild("NotPreferred")
    if notPreferred ~= nil then
        return 0
    else
        return 1
    end
end

local function sortByPreferred(path, route)
    table.insert(preferredPaths, ([path] = route,) --this gives a red line
    table.sort(preferredPaths, function(a, b)
        local ca, cb = convert(a), convert(b)
        return (cb < ca)
    end)
    return preferredPaths[1]
end

Correct me if I'm wrong, but I didn't bother explaining what the parameters mean. I think I should just put out there that I want the path and the route to be paired together in the table preferredPaths, so that I can sort the table based on whether or not a child named "NotPreferred" belongs to the route. You could tell me how to add the pair of values to my dictionary, or just tell me how to do everything if you're feeling generous. Thanks!

0
You dont a dictionary just has key and value ou just set the key to a value preferred Paths[path] = route User#5423 17 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

just create a value just like how you would index one, and set the index and value of it

ex

local dictionary = {}

dictionary["newValue"] = false -- or

dictionary.newValue = false
Ad

Answer this question