Problem iterating nested table with key value pair

Hi, How can I iterate over the nested table this is my code

each element of inner table has 4 properties when I run this code I get only three elements with some weird characters.

output:

00:01:23.178  1    table: 0E244440
00:01:23.178  2    table: 0E244328
00:01:23.178  3    table: 0E244350
 

code:

   local table={
    {
        name=“platform”,
        id=p,
        x=100,
        y=200,
    },
    {
        name=“RedGem”,
        id=r,
        x=100,
        y=200
    },
    {
        name=“bgem”,
        id=b,
        x=100,
        y=200
    }
}

    for k,v in pairs(table) do
        print(k,v)  – print(k,table[v])
    end

  1. You can’t have a table named table to start with (table is a reserved word)

  2. Please (always) format code posts (thanks):

formatyourcode.jpg

Try this:

local t = { { name = "platform", id = p, x = 100, y = 200, }, { name = "RedGem", id = r, x = 100, y = 200 }, { name = "bgem", id = b, x = 100, y = 200 } } for k,v in pairs( t ) do print( k, v.name, v.id, v.x, v.y ) end

SSK 2offers two table utilities if you want to use just the code from my extensions:
 
https://roaminggamer.github.io/RGDocs/pages/SSK2/extensions/#table-debug-features

 

-- Dump first level of table table.dump( t ) -- Iteratively dump table table.print\_r( t )

Code for table.* extensions from SSK 2:
https://github.com/roaminggamer/SSK2/blob/master/ssk2/extensions/table.lua

Depends on string extensions:
https://github.com/roaminggamer/SSK2/blob/master/ssk2/extensions/string.lua

and io.* extensions:
https://github.com/roaminggamer/SSK2/blob/master/ssk2/extensions/io.lua

If you want just print out table use print_r function from Rob Miracle. I use it my recent project.

thanks for the reply I just didn;t notice that, but its working with table as tablename what actually didn’t work was value of v in for loop was not as expected but v.attribute worked

Note: You are allowed to call your table ‘table’, but you risk wiping out your access to the table library if you do that.

i.e. If you do this:

table = { 1, 2, 3, "my table" }

You will no longer be able to call the table library because you replaced the reference.

  1. You can’t have a table named table to start with (table is a reserved word)

  2. Please (always) format code posts (thanks):

formatyourcode.jpg

Try this:

local t = { { name = "platform", id = p, x = 100, y = 200, }, { name = "RedGem", id = r, x = 100, y = 200 }, { name = "bgem", id = b, x = 100, y = 200 } } for k,v in pairs( t ) do print( k, v.name, v.id, v.x, v.y ) end

SSK 2offers two table utilities if you want to use just the code from my extensions:
 
https://roaminggamer.github.io/RGDocs/pages/SSK2/extensions/#table-debug-features

 

-- Dump first level of table table.dump( t ) -- Iteratively dump table table.print\_r( t )

Code for table.* extensions from SSK 2:
https://github.com/roaminggamer/SSK2/blob/master/ssk2/extensions/table.lua

Depends on string extensions:
https://github.com/roaminggamer/SSK2/blob/master/ssk2/extensions/string.lua

and io.* extensions:
https://github.com/roaminggamer/SSK2/blob/master/ssk2/extensions/io.lua

If you want just print out table use print_r function from Rob Miracle. I use it my recent project.

thanks for the reply I just didn;t notice that, but its working with table as tablename what actually didn’t work was value of v in for loop was not as expected but v.attribute worked

Note: You are allowed to call your table ‘table’, but you risk wiping out your access to the table library if you do that.

i.e. If you do this:

table = { 1, 2, 3, "my table" }

You will no longer be able to call the table library because you replaced the reference.