Dynamic object names possible?

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:
[lua]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[/lua]
The function call should look like this:
[lua]changeButtonStat(true, “button1”)[/lua]

Please help me! I’m actually a Flash programmer and I know in Flash it’s easy to do this. I cannot imagine that it’s not possible with lua.

Thanks a lot!

Vincent [import]uid: 50639 topic_id: 16331 reply_id: 316331[/import]

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. [import]uid: 8271 topic_id: 16331 reply_id: 60823[/import]

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,

?:slight_smile:

[1] http://howto.oz-apps.com/2011/09/creating-dynamic-variables.html [import]uid: 3826 topic_id: 16331 reply_id: 60842[/import]