Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I use table.insert on a dictionary?

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!

1 comment

0

You dont a dictionary just has key and value ou just set the key to a value preferred Paths[path] = route

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.