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

Is it possible to create table dictionaries with more then one response?

Asked by
UPumpkin -34
5 years ago

For example

hi = {

["sup"] = "100","300"

}

Would it be possible to make it choose between the first and second of the ones listed, for example how would I make it so the 300 prints and how would I make it so the 100 prints. Assuming this is possible.

2 answers

Log in to vote
1
Answered by
gullet 471 Moderation Voter
5 years ago

You simply put a table in a table. If you want to index at random you can use the Random type to generate random index.

local outer = {
    ["inner"] = {"100", "300"}
}

print(outer["inner"][1])
print(outer["inner"][2])
Ad
Log in to vote
0
Answered by 5 years ago

This is what I usually do to solve this dilemma.

local Foo = {
    Bar = {"100", "300"},
    Baz = {math.sqrt(-1)^2}
}

print(Foo.Bar[1]) -- 100
print(Foo.Baz[1]) -- should be -1, but may be -nan(ind)

Answer this question