#Help
1 messages · Page 1 of 1 (latest)
You could ask ai for explanation, however I'll try my best to explain it. Pairs returns a table of the given instance:GetChildren() with number indexes, like this: { 1 apple,
2 pear,
3 lemon}
Ipairs does the exact same but excludes the numbers. I hope it was explained well (don't mind me getting anything wrong)
you dont even need to use ipairs or pairs
i dont think ive ever used it since i learned it from a tutorial like 2 years ago
facts
you're sorting through a list of things in "pairs".
Let's say the first thing in the list is an apple, the second is an orange, and the third is a banana.
so your list in code is:
local mylist = {apple, orange, banana}
Now here's an example of a pairs loop for this list:
for i, v in pairs(mylist) do
print(i)
print(v.Name)
end
-'i' is the index of the item (what number is it in the list? apple would be 1, orange would be 2)
-'v' is the object itself.
-'pairs' is just pairs of objects and their index.
-after 'pairs' in the parenthesis, you put whatever list you want to look through.
So in english the loop I wrote above means:
for each item in mylist, print its position in the list and its name.
ipairs is the same thing but it always sorts through the list in order from start to end, while normal pairs sorts in random order.
Im not using it ever since I saw a dude better than me method of for loops
doesnt that work the exact same without pairs though
yeah it's optional now but thats the concept he was asking about
depends on if you want to specify pairs or ipairs
what
for ordered data types, excluding pairs will automatically work as ipairs
for non ordered types like a dict it will works as pairs
