[solved] Gui buttons - can they tell a function which Local to use?

Hi, I’m working on simplifying a really crude script I’ve got going – I’ve created a little effect column cheatsheet GUI window (or, actually, updated it for the new effects - yes, it was an ancient bit of code ;)/> )
so I’m wondering, since I have buttons that automatically write an effect value to an effect column, how could I simplify it?

Currently each button calls a separate function, and each function has “local i = effect value” and then i is put to that effect column. but i’m wondering, surely there should be some way that the vb:button could say “hi, i’m this” and then i would just have one single function that spews forth the required effect column command.

… In fact, I think I just got an idea.

You have a problem, you rush to the forum and while typing, you suddenly realize something…I think I know the feeling… :slight_smile:

Anyway, so you’ve set up the buttons to call a function with no arguments? Like this:

pressed = SomeFunction  

(where the SomeFunction is declared elsewhere)

The solution would be to declare an anonymous method that handle the click:

pressed = function()  
 -- call your method with some extra argument(s)  
 SomeFunction("arg1",42)  
end  

Bonus info: you can also identify any button across the scope of your script, e.g. to hide it or do something fancy with the user interface.
It’s simple, really, just a matter of assigning an id to the button. Once the button has an id, you can refer to the button itself within it’s own handler, or from anywhere else

  
-- Useless example: make a button invisible when pressed  
  
local vb = renoise.ViewBuilder()  
local view = vb:button{  
 id = "my_object_id",  
 pressed = function()  
 local my_object = view["my_object_id"]  
 my_object.visible = false  
 end  
}  
  

Hi, I decided to go the function name(bla,bly) way, and it seems to work, kinda. I can define a button to send “0A”, and it writes it to the effect column. but erasing doesn’t seem to work. Here’s what i have:

function effect_write(effect,effectstatus)  
local s = renoise.song()  
local w = renoise.app().window  
local efc = s.selected_effect_column  
 --s.selected_effect_column_index=1  
local status="0Axy - Arpeggio (x=base note offset1, y=base noteoffset 2) *"  
local i=effect  
 if efc==nil then  
 return  
 else  
 if efc.number_value==effect then  
 efc.number_string=00  
 efc.amount_value=00  
 else  
 efc.number_string=i  
 efc.amount_value=00  
 renoise.app():show_status(status)  
 end  
 w.active_middle_frame = 1  
 w.lock_keyboard_focus = true  
end  
end  

if the selected effect column is empty, a 0A00 gets written when i press the button. but if i press the button again, nothing happens, not even an error. what am i doing wrong?

edit…

  
 if efc.number_value==effect then  
 efc.number_string=00  
 efc.amount_value=00  
 else  
 efc.number_string=i  
 efc.amount_value=00  
  

The catch was, of course, that it needs to be

efc.number_string="00"  

for it to work.

now if only i could figure out how to use the effectstatus button command to define which status to show.

okay, was able to get the effectstatus to show too.
so basically it was just linking to function CheatSheet (Effect, EffectStatus)
and then having the EffectStatus dictate which effect was shown with a bunch of local work.
I’ll optimize it tomorrow, and hopefully post a version.