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.