Hi,
Is it possible to use dynamic object names?
My app has 7 different buttons. Each button has an "off", "on" and a "standard" status. Every status uses another image.
I would like to create one function with which you can change the state of every button.
One button has 3 objects, for example:
button1_standard
button1_on
button1_off
I want a function like this:
1 2 3 4 5 6 7 8 9 | function changeButtonStat(isOn, buttonName) if isOn then [buttonName .. "_on"].isVisible = true [buttonName .. "_off"].isVisible = false else [buttonName .. "_on"].isVisible = false [buttonName .. "_off"].isVisible = true end end |
You want to reference the objects (known in lua as tables) with braces, not square brackets. Otherwise, your code is actually correct.
I would, however, use .alpha = 0 and .alpha = 1, not .isVisible.
Take a look around the sample code and you will see plenty of examples doing exactly what you want.
Vincent, you might want to read up on this article [1]
it explains what you are after, this is the most commonly asked question on the forum by all new developers that do not search/read the forums if there was s similar issue.
That way a wealth of information that was shared by various developers and their experiences are lost to the person asking the question as that discussion will definitely not happen again.
cheers,
?:)
[1] http://howto.oz-apps.com/2011/09/creating-dynamic-variables.html