javascript in pasted bpatcher, loadbang method

Jun 28, 2012 at 2:29am

javascript in pasted bpatcher, loadbang method

Hello,
I am using a bpatcher for a widget, and it’s driven by a js object. I need the loadbang() method to execute when i copy and paste the widget, but it doesn’t seem to … loadbang() only happens when I create the bpatcher from scratch. Why is that? Is there an alternate method I should be using?
thanks,
geof

#41767
Jun 29, 2012 at 1:50am

Loadbang() only gets called when the patch initally opens. There might be an easier way to do it, but I’d probably do something like this:

function loadbang(){
   if(!alive){new Global('alive');}
   else{init();}
}

function init(){
  //whatever you had in loadbang()
}

//this will call the function whenever a new js instance is created in your patch
loadbang();

I haven’t used Globals for a while (I kinda try to stay away from them in m4l due to threading issues), and my syntax might be wrong, but the general idea should work.

#149009

You must be logged in to reply to this topic.