local presetbans = { ["ApocalypseRising927"] = {"Testing"}, ["Interzone"] = {"Testing Also"} }
There is my table for a ban system. I tried many different ways, but I could print the 'reasons'.
I can only seem to print the names, how would I get the names' "reasons/values"? Thanks for help! :D
Well, you'd first want to change them to a value format, currently you have them as a table.
local presetbans = { ["ApocalypseRising927"] = "Testing", ["Interzone"] = "Testing Also" }
now with the modified code, this means ApocalypseRising927
is the index of value Testing
. Now to print out the value, we would iterate through the table's contents using the pairs
function.
local presetbans = { ["ApocalypseRising927"] = "Testing", ["Interzone"] = "Testing Also" } for index, value in pairs(presetbans) do print(index,value) end
technically this script would print out both the indexes and values.
local presetbans = { ["ApocalypseRising927"] = {"Testing"}, ["Interzone"] = {"Testing Also"} } print(presetbans["ApocalypseRising927"][1]) print(presetbans["Inerzone"][2])
If you wanted, you could just do ["Name"] = "Testing",
That way you can just say print(presetbans["Interzone"]) and automatically get your reason but this should work.
You basically have a table inside of a dictionary inside of a table.
So print(presetbans) would print the table.
print(presetbans["Interzone"]) Would print the table inside of this dictionary.
For the data in the table we add the [1] to reference the reason inside of that table.