Announcement

Collapse
No announcement yet.

Table questions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Table questions

    Hey there all

    I have a table

    Code:
    TableName.Subtable = {
            [4] = {
            Name = '',
            Sec = ''
            },
            [89] = {
            Name = '',
            Sec = ''
            }
    I want to loop throw the [] returns but there not in number order but they are numbers
    and they don't have some numbers in it

    like 4,7,12,89

    I also need to return that number
    so when I loop throw

    Code:
    for x, j in pairs() do
       
    end
    the x is the index but does it just loop throw them and will x but the name or will it just be a number count?
    Plugins or Sources MokoX
    BunnyHop 2021 Here

  • #2
    Is there no takers on this or have I explained myself wrong?
    Plugins or Sources MokoX
    BunnyHop 2021 Here

    Comment


    • #3
      Tables contain values, each value has an index to describe where it is in the table.

      if you don't set any indexes they are set automatically.

      E.g

      tMyTable = {"Fred", "Bob", "Jim", "Kingzooly"}
      the indexes are automatically set to 1, 2, 3, 4 etc...

      setting custom indexes is written like this

      tMyTable = {59="Fred", 67="Bob"}.

      Using a for loop the way you have shown the x would be the index and the j would be the value. So in my cutom index example:
      Code:
      for x,j in pairs(tMyTable) do
       -- Some Stuff
      end
      Some Stuff would execute once for x=59, j="Fred" and then again for x=67, j="Bob".

      In your example:
      TableName.Subtable = { [4] = { Name = '', Sec = '' } [89] = { Name = '', Sec = '' }

      You have tables inside a table so the for loop would execute differently depending on which table you referenced.

      I would suggest using:
      Code:
      for x,j in pairs(AnyTableYouFancy) do
      Dialog.Message(x, j);
      end
      to determine exactly what is going on.

      Hope this helps

      Comment


      • #4
        Originally posted by HobbsyJr View Post
        Tables contain values, each value has an index to describe where it is in the table.

        if you don't set any indexes they are set automatically.

        E.g

        tMyTable = {"Fred", "Bob", "Jim", "Kingzooly"}
        the indexes are automatically set to 1, 2, 3, 4 etc...

        setting custom indexes is written like this

        tMyTable = {59="Fred", 67="Bob"}.

        Using a for loop the way you have shown the x would be the index and the j would be the value. So in my cutom index example:
        Code:
        for x,j in pairs(tMyTable) do
         -- Some Stuff
        end
        Some Stuff would execute once for x=59, j="Fred" and then again for x=67, j="Bob".

        In your example:
        TableName.Subtable = { [4] = { Name = '', Sec = '' } [89] = { Name = '', Sec = '' }

        You have tables inside a table so the for loop would execute differently depending on which table you referenced.

        I would suggest using:
        Code:
        for x,j in pairs(AnyTableYouFancy) do
        Dialog.Message(x, j);
        end
        to determine exactly what is going on.

        Hope this helps
        Yes and no lol I will have to do like you said do a test, I just been busy with BunnyHop I just not had time to test it but I think it will work the way I was hoping now you have explained it little better then the help file did lol
        Plugins or Sources MokoX
        BunnyHop 2021 Here

        Comment

        Working...
        X