Do I always have to do for i,v in pairs
when trying to see whats inside a table and detecting specific item or can I do print(Table[Item])
Yes you can do print table[indexofelement] and you should be good.
so can I do something like if Table[plr] then
Yes absolutely that would work are you just trying to see if there is an element at that indice of the table?
Hey, I suggest you take a look at the Tables article of developer.roblox.com website, It covers some of the table issues!
To index you can also do table.Item or table[item], However, I only think the first way works for dictionaries, correct me if I’m wrong.
Yes the first way only works for dictionaries. And you cant do table.item since the item would technically be at an indice. However table[jndice] is also the same as
table.indice in certain cases.
So if you were checking over a table that is constructed like so
local testTable = {
testIndice = "whatever"
}
If you indexed it like…
testTable["testIndice"]
Would work the same as
testTable.testIndice
So in summaryit would look like this:
local CoolDictionary = {
hamburger = "Food"
}
local CoolArray = {"Hello There!", "I hope you have a nice day"}
print(CoolTable.hamburger) -- same thing as CoolTable[hamburger]
print(CoolArray[2]) -- I hope you have a nice day, gets printed out because it's the second item in the array.
And that’s basically how you index an array and a dictionary. Also if you don’t know, a dictionary just is a key value pair system, so if you wanted to state a type of animal for example, you could say something like: animal = “dog”. An array is simply a list of items that you can control, you can put anything in an array, functions, objects, etc.
You can use table.find():
local table1 = {"Candy", "Noob", "Carmel"}
local findItem = table.find(table1, "Noob")
print(findItem)
It’ll return nil if it can’t find an item in a table.
depends on if ur table is an array or dictionary
array -
{345,245,2345}
dictionary-
{
["Key"] = 123
}
if u do print(table[plrname]) on a dict it will print whtever value u assign it meanwhile for arrays u gotta put which place it is in the array for ex-
--here we gonna print rot in hell
local table = {"pls dont print","pls pls dont print","rot in hell","lol idc"}
print(table[3])
I always use
if table.find(Table, itemToFind) then
print("Found!")
end
I prefer just indexing the table, I don’t really think that table.find is any use to me, I don’t know if it’s better or not, but what’s the point of using table.find?
table.find is used to find the index of a value. Sometimes you don’t have the index, and only the value. This might be helpful.