ipairs vs pairs - Roblox Scripting Tutorial

Поделиться
HTML-код
  • Опубликовано: 16 янв 2025

Комментарии • 47

  • @pieTone
    @pieTone 2 года назад +23

    Many ppl don't really understand those, great you made a tutorial on them!

    • @5uphi
      @5uphi  2 года назад +4

      hopefully it help

    • @Smurfis
      @Smurfis Год назад

      @@5uphithe way you showed the array image really helped me personally that's the part I needed to “get over” thank you so much.

  • @yoursubconscious1774
    @yoursubconscious1774 2 года назад +14

    Thanks this is really helpful because I was trying to make a shop system where you can press previous and next to move the camera and I made a table for every part in the folder(which isn’t really good) ipairs would be a good idea for this since it goes in order and when I tried to use regular pairs it didn’t go in order and indexing was a major part of it

  • @quackoramic
    @quackoramic 2 года назад +2

    I knew this, but it is interesting to see how you explained it. Very great video!😄

  • @AzureSpike
    @AzureSpike 9 месяцев назад +2

    "cake = yuck"
    "broccoli = yummy"
    bros caseoh's worst nightmare 💀

  • @xdcrackings
    @xdcrackings 2 года назад +2

    great vid but the audio bro i cant explain where i feel it, i feel it in my soul

  • @FlamingoSomehow
    @FlamingoSomehow 2 года назад +1

    thank you for this. i noticed that when i used pairs, it had a random index for strings and wondered why

  • @ipairs
    @ipairs 10 месяцев назад +3

    ipairs

  • @kennethkline7702
    @kennethkline7702 2 года назад +4

    I think there's another issue with using eye pairs if there is a gap in between The index values. For example, if there was only 1, 3 and 4. Also, I think there is an issue with "nil" as well.

    • @5uphi
      @5uphi  2 года назад +7

      That's not a issue it's just how it works if you have a table with the keys 1,2,3,5,6,7 the length of that table will be 3 and when you use ipairs it will loop upto 3 and no more but if you use pairs then the order might not be correct so only use ipairs if your table has no gaps in it

    • @kennethkline7702
      @kennethkline7702 2 года назад

      @@5uphi ah, thanks so much for the clarification!

  • @EliteUTTV
    @EliteUTTV 6 месяцев назад +1

    fast explaination of the whole vid:
    ipairs goes in order while pairs dosen't

  • @nwhatchel
    @nwhatchel 2 года назад +3

    How did you research pairs and ipairs to gain your own understanding of it? Did you go thorough the documentation?

    • @5uphi
      @5uphi  2 года назад +4

      When I first started learning lua I first did a simple google to pairs vs ipairs but mainly understood them by simply using them

  • @dav74977
    @dav74977 2 года назад +4

    THE ORDA

  • @randomb_oi8787
    @randomb_oi8787 2 года назад +1

    roblox recently made it so the iterator isnt necessary, you can just do for i,v in myTbl do

    • @5uphi
      @5uphi  2 года назад

      Correct that is just like using pairs

  • @Unknown-ym3ds
    @Unknown-ym3ds Год назад +1

    How many years of experience you have?

  • @dhruv6489
    @dhruv6489 2 года назад +1

    So what change does it make? ipairs doesn't print strings or smthing

    • @5uphi
      @5uphi  2 года назад +1

      Ipairs only loops upto the table length
      So let's say you have a table with the keys
      1,2,3,7,9
      Ipairs will only go upto 3 because the length of the #table will be 3
      Also ipairs loops in order
      But the order of pairs is undefined

    • @dhruv6489
      @dhruv6489 2 года назад

      @@5uphi Why is the length of the table till 3 only?

    • @5uphi
      @5uphi  2 года назад

      That's just how lua tables works because the key 4 is missing it only goes upto 3

    • @dhruv6489
      @dhruv6489 2 года назад

      @@5uphi Alr ty

    • @5uphi
      @5uphi  2 года назад

      No problem I'm sure there is a technical reason why lua did it like that but I don't know what lua is doing behind the scenes

  • @AzureSpike
    @AzureSpike 8 месяцев назад

    what is the difference between using regular for loop and pairs loop?

    • @5uphi
      @5uphi  8 месяцев назад

      It's equivalent to using pairs

  • @GattoBIN
    @GattoBIN 2 года назад +1

    Now i know this, thanks.

    • @5uphi
      @5uphi  2 года назад +1

      No problem

  • @goreacraft
    @goreacraft 2 года назад

    do this 4 different types of iteration behave differently if the lists are modified while iterating?

    • @5uphi
      @5uphi  2 года назад

      well you can think of them as 2 types of iterations I'm just showing you how the other 2 work behind the hood.
      yes they behave differently
      the main one you need to be carful of is adding values to the table when using pairs as there is a chance it will iterate over the same key multiple times but its safe to remove values when using pairs

  • @qxxrd
    @qxxrd 2 года назад

    hey can you also explain "next"? (ex. for i, v in next, workspace:GetChildren() do ....... end)

    • @5uphi
      @5uphi  2 года назад

      I kinder already did in the video next(workspace:GetChildren()) gets the first item in the linked list. When you use it in the for loop it works just like pairs

  • @cryo_doesstuff
    @cryo_doesstuff 2 года назад

    Can you tell where are those mostly use?
    I am still confuse, like why use for loops?

    • @5uphi
      @5uphi  2 года назад +1

      If you look at my snake game video I talk about for loops in that video

  • @efemimec
    @efemimec Год назад

    with luau you don't even need either

  • @brokemono
    @brokemono 2 года назад +1

    I don't know when I picked this up but I always use "for i, v in next, mytable do"
    So far it works fine...Some people say I should use ipairs instead.

    • @5uphi
      @5uphi  2 года назад +6

      try to not take what others say seriously just do you

  • @renzyh
    @renzyh 2 года назад +1

    you're helpful on god