Parameter values in objects

Brand new to Codea and love it. I mentioned how cool it is in a keynote talk I gave Wednesday, and folks were interested. Still very beginner in Codea and Lua, but have been programming for a half-century and am starting to get fairly good at it.

I plan to have a few objects on screen. Think sprites, tho they aren’t. I want to adjust some of their parms as the program runs, using parameter(). Looking for more ideas than:

  1. Have parameter p1, p2, and so on, and each object knows the one to check. Should work, just kind of grubby. Is there a way, given a string, to read the variable of that name, so I could do something like

parameter(“ParmName”, 0, 100)

obj = Object(“ParmName”)

And then inside the Object, fetch that parameter value by name?

  1. Have one parameter x, another objectNumber, and each object checks to see if objectNumber is set to his number and uses x if it is. Might be a good idea to highlight the one the objectNumber points to. With this idea I’m concerned the user will set values in the wrong order, but it would perhaps allow for more options and objects.

Other thoughts, please?

@RonJeffries, you could use loadstring. http://www.lua.org/pil/8.html

function setup()
    thisisavariable = 123
    local var = "thisisavariable"
    local val = loadstring("return "..var)()
    print(val)
end

Thanks … A bit of a big hammer, but one way or another I guess it has to be something like that.

I suppose vars are passed by value, not reference? I’ll read a bit more …

Thanks again.