Problem With Classes And Button Notifiers

hey,

i having some issues with released notifiers from buttons inside a class instance, that call a function from an instance of a different class, which in return accesses the calling instance as well as other instances of the same class.

since this might sounds confusing, and one would ask why the f you would want to do that, i will try to explain what exactly is going on.

first, we have a class LEDButton which has a function get_control(properties) that returns a view, containing an “led” and a button, with the provided properties.
this class provides two modes of function: either it toggles the led itself (mode = “toggle”), then calls the released notifier, or it only calls the released notifier without changing the led’s state (mode = “manual”).

now we have a second class LEDButtonChooser, that is intended to turn a group of LEDButton instances into a radio button styled set.
this class has a function make_chooser(args), that expects a table led_buttons of all LEDButton instances and optionally the index value as argument (1 is default). furthermore, each LEDButton instance needs to include the function LEDButtonChooser:set_value(value) in its released notifier.

now the problem is: the LEDButton class should work flawlessly, i thoroughly tested it. unfortunately, the LEDButtonChooser class doesn’t work as intended, when the function LEDButtonChooser:set_value(value) is called from a released notifier of a button contained inside a LEDButton instance.

i tried hard to find the reason, but i guess it has to do with passing self. i really double-checked that every call uses “:”, so self should always get passed, but something goes wrong.

since the LEDButton class needs two icons for displaying the “led”, i will provide an example xrnx.

thanks a lot for your effort!

The issue is in main.lua:65

You create an instance of the LEDButtonChooser class (as led_button_chooser) on line 22

However, the call to make_chooser() (line 65) is for a new class instance (LEDButtonChooser rather than led_button_chooser).

Changing this fixes the code.

As per IRC discussion, double storing of parameters is probably a bad idea.

Also, make_chooser can be an override of __init() if you so wish to avoid this bug occuring again.

as per irc discussion, thank you very much =D

will clean out that code and also write a new chooser that generates the ledbuttons itself.