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

How would I print my table's values?

Asked by 7 years ago
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

2 answers

Log in to vote
2
Answered by
rexbit 707 Moderation Voter
7 years ago
Edited 7 years ago

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.

Ad
Log in to vote
1
Answered by 7 years ago
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.

0
Interzone* Apologies. BStandsForBuilding 115 — 7y
0
Should be "print(presetbans["Interzone"][1])" not 2, as you want to print the reason which is the first value User#13152 0 — 7y

Answer this question