I think this is basic, how do i get every item inside a table? I tried some scripts, but they didn’t work, or some of them were messy, thanks for reading.
Can you elaborate “every item?”
With that i mean find everything inside the table, i don’t know how they are called:
local MyDumbTable = {43,24,3242,45,46,5,23,456,3456,7,6543,567,8643,45467}
You can obtain any object from a table using it’s index.
For example:
a = {"test", 2323, game.Workspace, 123}
print(a[1]) -- "test"
print(a[3].Name) -- "Workspace"
print(a[4]) -- 123
What’s the use case here? You can use unpack(table) and that would allow you to place everything inside of it to a variable, such as:
local Tab = {1,5,3}
local Num1,Num2,Num3 = unpack(Tab)
--Num1 = 1
--Num2 = 5
--Num3 = 3
Or do what TokoNanami said if that’s what your use case is.
@TokoNanami @ShadokuSan
I don’t want to do it manually, what i want to do is get them manually, because in the current script i’m working, some players must touch a button, and a table will get the name of the players who touched the button, i don’t think that i will get an exact number of players who touched the button, so that’s why i want this automatically.
A table can’t get the name of a player, because a table is not a function, try to be more precise in your problem description because it’s hard to understand what you mean.
What is more, to get the name of a player who touched the button you can do it in many simple ways depending on whether the button is a GUI button or a part in the workspace.
Well, that issue with the player’s name should be my problem, but this is how it should look:
local PlayersTouched = {Conejin_Alt, Roblox, noob}
This is an example, where there can be many different amount of users who touched that button:
local PlayersTouched = {ZeroTwoYes, bob, ResponderReportar, Kakusmainsi}
local PlayersTouched = {Roblox}
local PlayersTouched = {}
local PlayersTouched = {MyMotherIsGod, MyFatherIsGod, ILoveCheese}
So basically, if i use your script, i would have to set a specific number of players, which means that i might not get the 4 players, i will get 3.
Let’s take an example of using folders:
< Players
_< Player1
_< Player2
_< Player3
So, what i would do in this circumstance, to get all folders, i would use a for i,v do script.
Well, what i want to do is something similar to that example, but instead of folders, i want to use this in tables. But i don’t know if using for i,v do is possible, i don’t even know how to do that. I hope this help and sorry by misunderstanding you!
Yes, you can:
a = {9, 99, 999}
for i,v in ipairs(a) do
print(i, v)
end
-- 1 9
-- 2 99
-- 3 999
By the way when you iterate through these folders you are also doing an iteration on a table, because you do:
for i,v in pairs(folders:GetChildren()) do end
where folders:GetChildren() returns a table containing your folders.
I think you mean something like:
for i=1,#YourTable do
local Item = YourTable[i]
—insert what to do with the item here
end
not sure though.
(post deleted by author) ᅟ ᅟ ᅟ
It doesn’t matter if it’s a i,v or k,v loop. It might as well be d,b loop.
(post deleted by author) ᅟ ᅟ ᅟ
i - index in an array
k - key in a dictionary
Just in case any of the above doesn’t quite help you, and if you’re confused about tables, try taking a look at these pages:
Those should tell you whatever you need to know about making use of tables.
function getItems(tableInputted: table)
return table.unpack(tableInputted)
end
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.