Accessing numerically indexd table inside a numerically indexed table

Discuss any general programming issues here
Post Reply
zylesea
Posts: 204
Joined: Tue Feb 16, 2010 12:50 am
Location: Westfalen/Germany
Contact:

Accessing numerically indexd table inside a numerically indexed table

Post by zylesea » Thu Nov 22, 2018 11:27 pm

I am stuck in accessing content of a numerically indexed table within a numerically indexed table.

So far from the documentaion the case is clear with name indexed tables within a numerically indexed table

Code: Select all

buts = { {x1 = 0, y1 = 0, x2 = 100, y2 = 50},
            {x1 = 100, y1 = 0, x2 = 80, y2 = 50},
            {x1 = 180, y1 = 0, x2 = 100, y2 = 50} }

 For k = 0 To 2
          Debugprint (buts[k].x1, buts[k].y1, buts[k].x2, buts[k].y2)
  Next
But how to access the table's conent if the subtables are numerically indexed, too?

Code: Select all


buts = { { 0,  0,  100,  50},
            {100,  0, 80,  50},
            {180,  0, 100, 50} }

 For k = 0 To 2
          Debugprint (buts[k].[0], buts[k].1, buts[k] [2], buts.k[3])
  Next

All four versions written after Debugprint fail... The table gets initialized though, Listing content of buts shows their addresses, and I can even get the table lenght subtables with TableItems(buts[k]. But how to retrieve the actual content of these subtable fields?

p-OS
Posts: 115
Joined: Mon Nov 01, 2010 11:56 pm

Re: Accessing numerically indexd table inside a numerically indexed table

Post by p-OS » Fri Nov 23, 2018 1:29 am

Code: Select all

buts = { { 0,  0,  100,  50},
            {100,  0, 80,  50},
            {180,  0, 100, 50} }

 For k = 0 To 2
          DebugPrint (buts[k][0] .. " " .. buts[k][1] .. " " .. buts[k][2] .. " " .. buts[k][3]) 
 Next

zylesea
Posts: 204
Joined: Tue Feb 16, 2010 12:50 am
Location: Westfalen/Germany
Contact:

Re: Accessing numerically indexd table inside a numerically indexed table

Post by zylesea » Fri Nov 23, 2018 9:05 pm

Hi p-OS, thanks for pointing me to the right syntax. I had tried that (see example) but must have done some typing/stupid other error because it failed before. With your confirmed syntax I tried once again and - hooray - it works.

Post Reply