Help with Decision Chooser

Hello. I would like some help with my decision chooser, please. I’m trying to make a program where theres a parameter string where I can write how many options there are (it’ll convert the string to an integer or if it can’t, it’ll pretend it’s 2). Then theres a parameter button that you press, and it clears the parameters and then places parameter strings, that you can type in, and then the program puts a button parameter that you can press and the program will choose one of the parameters and print out that parameter’s value. Here’s what I got so far:

-- Decision Chooser

-- Use this function to perform your initial setup
function setup()
    ds = {}
    parameter.text("Options","2")
    parameter.action("Set Parameters",function()
        local o = math.tointeger(Options) or 2
        setParameters(o)
    end)
end

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

    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    for i=1, #ds do
        Option_..i = ds[i] -- error message here: syntax error near ".."
    end
end

function setParameters(amount)
    am = amount
    parameter.clear()
    parameter.action("Choose",choose)
    for i=1, amount do
        table.insert(ds,i,"")
        parameter.text("Option_"..i,ds[i])
    end
end

function choose()
    print(ds[math.random(1,am)])
end

The problem is that I’m not sure how to set a variable with a name depending on what another variable equals. Look in the for loop in draw to see what I mean.

It is possible to do this using loadstring, but I think a simpler alternative is to put ALL the options in one text field, and then use a slider to choose which one you want, ie

--suppose the alternatives are
ds={"option 1","option 2","option 3"}
--then create a string
txt=""
--number the options and insert line feeds
for i=1,#ds do txt=txt..i..". "..ds[i].."\
" end
parameter.text("Options",txt)
parameter.integer("Choose",1,#ds,1)

--EDIT you will need an action button too
parameter.action("Proceed",MakeChoice)

@Kolosso I’m not quite sure what you’re trying to do, but I took your original code and modified the functions to do what I think you want.

-- Decision Chooser

function setup()
    ds = {}
    parameter.text("Options","2")
    parameter.action("Set Parameters",
        function() amt=math.tointeger(Options) setParameters(amt) end )
end

function draw()
    background(40, 40, 50)
end

function setParameters()
    parameter.clear()
    parameter.action("Choose",choose)
    for i=1,amt do
        parameter.text("Option"..i)
    end
end

function choose()
    local xx={}
    for i=1,amt do
        loadstring(string.format("str=Option%d",i))()
        table.insert(xx,str)
    end
    print(xx[math.random(1,amt)])
end