Ipair (table)

Newbie require help
Need help to figure out how to use the ipair(table).

For k,v inpairs(table)
Blah
End

Figured out how to use it basics, but can someone help me to figure out how to assign a variable to ( table ) so I can use the same routine without having to write separate code.

Thanks

Is this what you’re after.


function setup()
    tabA={2,4,6,8,10}
    tabB={1,3,5,7,9}
    
    print("\
table A")
    showTable(tabA)
    
    print("\
table B")
    showTable(tabB)
end

function showTable(tab)
    for k,v in pairs(tab) do
        print(k,v)
    end
end

This is what I have so far - I used Cider to create the main screen, it does its job the you make your selection (mess) which has 3 tables in routine ( G, G2, Notes ). I managed over the week end to read 1 selection and notes ( ables to change between the two) but when I start adding in other selections it errors out with Table text.

function Message()
    background(231, 230, 231, 255)
    fontSize(14)
    textMode (CORNER)
    fill(0, 0, 0, 255)
    text ("Table :- "..subtable,15,740)
    text(mess,200,740)

    textMode (CENTER)
    button2001:draw()
    button2002:draw()
    button2003:draw()
    button2004:draw()
    button2005:draw()
    button2006:draw()
    button2007:draw()
    
    button3001:draw()
    
    if arrb[1] ~= "" then
        button2001.text = (arrb[1])
    end
    if arrb[2] ~= "" then
        button2002.text = (arrb[2])
    end
    if arrb[3] ~= "" then
        button2003.text = (arrb[3])
    end
    if arrb[4] ~= "" then
        button2004.text = (arrb[4])
    end
        if arrb[5] ~= "" then
        button2005.text = (arrb[5])
    end
        if arrb[6] ~= "" then
        button2006.text = (arrb[6])
    end
        if arrb[7] ~= "" then
        button2007.text = (arrb[7])
    end
    
    arrx = {25,100,700,800}
    if table.maxn ~= 0 then
        textMode (CORNER)
        for k,v in pairs(table) do
            --print (k,v)
            r = k
        end  
        --fill(65, 73, 228, 255)
        maxr = (r/4)
        y = 0
        for x = 1,maxr do
            xy = x*14
            text(table[x+y],arrx[1],650-xy)
            y = y + 1
            text(table[x+y],arrx[2],650-xy)
            y = y + 1
            text(table[x+y],arrx[3],650-xy)
            y = y + 1
            text(table[x+y],arrx[4],650-xy)
        
            --print(600-xy)
        end
        sr = 650-xy-20
        --print (sr)
        for k,v in pairs(notes) do
            --print (k,v)
            r = k
        end  
        --fill(113, 228, 64, 255)
        maxr = r
        y = 0
        for x = 1,maxr do
            xy = x*20
            text(notes[x],10,sr-xy)
        
            --print(x)
        end
    end                   

This is how I call the above, func - stops the main screen from being drawn
Table - the table I want to read
Mess - just for my purpose
Sw:draw() where the tables are stored

This works as is

if button2001:touched(touch) then
        func = "message"
        table = G
        mess = "lll.G."
        Sw:draw()
    end
    if button2002:touched(touch) then
        func = "message"
        table = G2
        mess = "lll.G.2"
        Sw:draw()
    end

But when I change
Table = (t)
And assign t a variable

Errors table string