Help by multiple tables

Hallo. Have a problem with tables. After entring a number, from multiple tables to a specific table can be selected. From this a llimitid number are displayed. An example follows. What is wrong in my Code?

-- Tables - need help
-- Use this function to perform your initial setup
function setup()
    print("Hello World!")
    --input n = 2  
    --input r = 5
    n=2; r=5
    --show number 5 in table t2 
    print("n = ",n)  --> 2  
    print("r = ",r)  --> 5
    m=("t" ..n .."[" ..r .."]")
    print("m = ",m) --> t2[5]
    p = m
    print("p = ", p) --> t2[5]
    print("t2[r] = ", t2[r]) --> 105
    print("p =",p) --> nil
    print("p1 =",p1) --> nil

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness

    -- Do your drawing here

I’m not totally sure what the syntax p=(m)[r] is meant to do. Is this something you’ve found on another lua site?

What it looks like you are trying to do is define a command by constructing it as a string and then executing it. This is what loadstring is for. So you could achieve this as follows:

local f = loadstring("p = t" .. n .. "[" .. r .. "]")

This will result in the desired outcome of 105.

An alternative which wouldn’t need loadstring would be to make the dummy index in your tables a real index. Thus start your code with:

t = {}
t[1] = {...}
t[2] = {...}
t[3] = {...}

or even just

t = {{...}, {...}, {...}}

Then you can simply put p = t[n][r].

Thanks for your quick help. The solution worked immediately. If one know how, every thing is simple. But for us newbies, it is often a big hurdle.
Fortunately there are experts like you.