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

Can a variable be given more than one value?

Asked by
Peeshavee 226 Moderation Voter
7 years ago

For an example can I do:

local hat = hit.Parent:FindFirstChild("Noob", "Pro", "Bob")

Or is this not possible? All help is appreciated!

4 answers

Log in to vote
2
Answered by
L43Q 48
7 years ago
Edited 7 years ago

I don't think it is possible, you'll need to use a table instead (http://wiki.roblox.com/?title=Table).

Ad
Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

You need to use a table, you will need this code:

hat = {"Noob" , "Pro" , "Bob"}

Then you need to use for i,v in pairs stuff, pls refer to tables in the wiki.

Click here to go to the wiki post about tables.

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago

No.

Imagine I had something like

friend = (Alice, Bob, Eve)

How could I answer questions about friend?

What is friend.Name? Answering just "Alice" or just "Bob" is wrong. Should we answer all three? In what order? What does, e.g., friend.Name:sub(#friend.Name) (the last letter of their name) mean? Is it ("e", "b", "e")? Or are the two friends different, meaning it's ("e", "i", "i", "", "b", "b", "", "e", "e")? Do we discard duplicates?

Is friend == Alice true, false? Or is it perhaps (true, false, false)?

If I insert friend into a list,

local list = {}
table.insert(list, friend)

How big is list afterwards? Does it contain 3 things, or 1? Is there an order of those things?


A value is a single object, but that object may be a collection of other values.

For example, a list or set of values can be represented as a table:

friends = {Alice, Bob, Eve}

We can now provide meaningful answers to these questions.

friends doesn't have a name, but each friend has a name:

for _, friend in pairs(friends) do
    print(friend.Name) --> Alice, Bob, Eve
end

friends == Alice is of course false, but we could write a function that lets us ask contains(friends, Alice) -- is Alice included in our list of friends?

Adding friends to a list just adds one thing -- this group of friends. But we can explicitly add each one individually, too:

for _, friend in pairs(friends) do
    table.insert(list, friend)
end
Log in to vote
0
Answered by 7 years ago

tables bruh

local hi = {"u", "ok"}

Answer this question