Arrays

Is there any way to print all values of an array ?

You could just use:

for j=1, #testArray do
print(testArray[j])
end

Is that what you’re looking for?

Check out this function:

function print_r ( t )
    local print_r_cache={}
    local function sub_print_r(t,indent)
        if (print_r_cache[tostring(t)]) then
            print(indent…"*"…tostring(t))
        else
            print_r_cache[tostring(t)]=true
            if (type(t)==“table”) then
                for pos,val in pairs(t) do
                    if (type(val)==“table”) then
                        print(indent…"["…pos…"] => “…tostring(t)…” {")
                        sub_print_r(val,indent…string.rep(" “,string.len(pos)+8))
                        print(indent…string.rep(” “,string.len(pos)+6)…”}")
                    elseif (type(val)==“string”) then
                        print(indent…"["…pos…’] => “’…val…’”’)
                    else
                        print(indent…"["…pos…"] => “…tostring(val))
                    end
                end
            else
                print(indent…tostring(t))
            end
        end
    end
    if (type(t)==“table”) then
        print(tostring(t)…” {")
        sub_print_r(t,"  “)
        print(”}")
    else
        sub_print_r(t,"  ")
    end
    print()
end

Rob always makes me have function envy :wink:

Don’t know that I could have written all that myself.  But copy-it-forward works fr me :slight_smile:

You could just use:

for j=1, #testArray do
print(testArray[j])
end

Is that what you’re looking for?

Check out this function:

function print_r ( t )
    local print_r_cache={}
    local function sub_print_r(t,indent)
        if (print_r_cache[tostring(t)]) then
            print(indent…"*"…tostring(t))
        else
            print_r_cache[tostring(t)]=true
            if (type(t)==“table”) then
                for pos,val in pairs(t) do
                    if (type(val)==“table”) then
                        print(indent…"["…pos…"] => “…tostring(t)…” {")
                        sub_print_r(val,indent…string.rep(" “,string.len(pos)+8))
                        print(indent…string.rep(” “,string.len(pos)+6)…”}")
                    elseif (type(val)==“string”) then
                        print(indent…"["…pos…’] => “’…val…’”’)
                    else
                        print(indent…"["…pos…"] => “…tostring(val))
                    end
                end
            else
                print(indent…tostring(t))
            end
        end
    end
    if (type(t)==“table”) then
        print(tostring(t)…” {")
        sub_print_r(t,"  “)
        print(”}")
    else
        sub_print_r(t,"  ")
    end
    print()
end

Rob always makes me have function envy :wink:

Don’t know that I could have written all that myself.  But copy-it-forward works fr me :slight_smile: