I have a table which contains a list of functions and I want to randomise the order of each value but using pairs DOES NOT WORK
I could use a randomising function to randomise the order of the table (theres a bunch online) but they rely on grabbing each value’s integer number and my table doesn’t have an integer for each function as it goes like this:
Tables (i.e. arrays) do have order.
Dictionaries (like in this person’s use case) do not.
In order to get a random function from the dictionary, you will need to use a for loop to get all the keys, then get a random key from the keys.
For example:
local Dict = {
["FFA"] = "function",
["Nothing happening"] = "function",
["Teamed"] = "function"
}
local Keys = {}
for key, _ in pairs(Dict) do
table.insert(Keys, key)
end
local RandomKey = Keys[math.random(#Keys)]
local Function = Dict[RandomKey]
Function()