javascript in pasted bpatcher, loadbang method


    Jun 28 2012 | 2:29 am
    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

    • Jun 29 2012 | 1:50 am
      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.