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

How Can I Find Items In A Variable Like This?

Asked by 3 years ago

I Don't Know How To Get Strings Out Of A Variable Like This

local names = {"a","b","c","d"}

thank you :)

1 answer

Log in to vote
1
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago

Those are called Tables, you can get values from them by indexing them, in your case you would do this

local names = {"a","b","c","d"}

names[1] -- a
names[2] -- b
names[4] -- d
names[5] -- nil

There is also a different type of values with keys instead of numbers, these types of tables look somehow like this

local SomeTable = {
    ['cat'] = 'something',
    ['john'] = 500,
    'a',
    'b',
    ['c'] = Instance.new('Part'),
    [Enum.NormalId.Top] = true,
}

SomeTable['cat'] -- something
SomeTable[Enum.NormaId.Top] -- true
SomeTable[2] -- b

You see values without index (In your case a, b, c and d, all of them) must be indexed with number which is called Index and refers to location of the element in the table.

Tables Tables Tables Tables

Ad

Answer this question