#Help

1 messages · Page 1 of 1 (latest)

lyric sapphire
#

I don't understand how pairs and ipairs work no matter how many videos i watch

#

im pretty dumb

hasty oasis
#

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)

scenic copper
#

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

rancid kestrel
main valley
# lyric sapphire I don't understand how pairs and ipairs work no matter how many videos i watch

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.

hasty oasis
trim terrace
main valley
trim terrace
#

so

#

is it just pointless

main valley
trim terrace
#

what

main valley
#

for ordered data types, excluding pairs will automatically work as ipairs

#

for non ordered types like a dict it will works as pairs

trim terrace