HISE Logo Forum
    • Categories
    • Register
    • Login

    (Possible) Breaking change: local variables references inside nested function definitions

    Scheduled Pinned Locked Moved General Questions
    75 Posts 10 Posters 5.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d.healeyD
      d.healey @Christoph Hart
      last edited by

      @Christoph-Hart That's nice, I've been in the same habit of declaring local versions

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      1 Reply Last reply Reply Quote 0
      • ustkU
        ustk @Christoph Hart
        last edited by

        @Christoph-Hart Can't capture anonymous expression

        Might be just normal, I'm not familiar enough with lambdas...

        for (t in things)
        {
        	bgPnl.setPaintRoutine(function [t](g){}); // Can't capture anonymous expressions
        
        	var thing = t;
        	bgPnl.setPaintRoutine(function [thing](g){}); // ok
        }
        

        Just for my personal knowledge, why is it anonymous?

        Can't help pressing F5 in the forum...

        d.healeyD Christoph HartC 2 Replies Last reply Reply Quote 0
        • d.healeyD
          d.healey @ustk
          last edited by d.healey

          @ustk t is anonymous, as in you didn't declare it. HISE just magicked it out of a nowhere when you needed it for your loop. What about this approach?

          function myPaintRoutine(g)
          {
              var things = this.data.things;
          }
          
          bgPnl.data.things = things;
          bgPnl.setPaintRoutine(myPaintRoutine); 
          

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          ustkU 1 Reply Last reply Reply Quote 1
          • ustkU
            ustk @d.healey
            last edited by

            @d-healey Thanks for clarifying
            Yeah, I can find a way to o what I need, it's just that for once I could find a purpose for using lambdas, disillusion... :)

            Can't help pressing F5 in the forum...

            d.healeyD 1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey @ustk
              last edited by

              @ustk Here's the kind of thing I use lambdas for

              inline function promptForSomething(name)
              {
                  Engine.showYesNoWindow("Would you like to view " + name + "?", function [name](response)
                  {
                      if (response)
                          show(name);
                  });
              }

              Libre Wave - Freedom respecting instruments and effects
              My Patreon - HISE tutorials
              YouTube Channel - Public HISE tutorials

              ustkU 1 Reply Last reply Reply Quote 1
              • ustkU
                ustk @d.healey
                last edited by

                @d-healey In fact I'm mistaken as I used it in another project the same way you do:

                inline function ondriverCbControl(component, value)
                {
                	Engine.showYesNoWindow(Titles.ChangeDriver, Messages.WarningDeleteCaptures, function[value](result)
                	{
                		if (result)
                		{
                			Settings.setAudioDeviceType(drivers[value-1]);
                		}
                	});
                };
                driverCb.setControlCallback(ondriverCbControl);
                

                But it's the first time I try in a for loop though...

                Can't help pressing F5 in the forum...

                1 Reply Last reply Reply Quote 1
                • Christoph HartC
                  Christoph Hart @ustk
                  last edited by

                  @ustk David is right, the iterator variable is not part of the function scope that can be passed to the lambda. Not sure if this is an oversight or if there is a good reason, but I always create variables like in the second line too. Think of it as picking up a nice bouquet in order to surprise your lambda friend.

                  ustkU 1 Reply Last reply Reply Quote 2
                  • ustkU
                    ustk @Christoph Hart
                    last edited by

                    @Christoph-Hart Love the analogy 🌻 :)

                    Can't help pressing F5 in the forum...

                    Christoph HartC 1 Reply Last reply Reply Quote 0
                    • Christoph HartC
                      Christoph Hart @ustk
                      last edited by

                      @ustk Yeah, it was definitely worth googling what that phrase sounds like in English...

                      ustkU 1 Reply Last reply Reply Quote 0
                      • ustkU
                        ustk @Christoph Hart
                        last edited by

                        @Christoph-Hart bouquet is a french word :)

                        Can't help pressing F5 in the forum...

                        d.healeyD 1 Reply Last reply Reply Quote 0
                        • d.healeyD
                          d.healey @ustk
                          last edited by

                          @ustk https://www.youtube.com/watch?v=FboWtJiNYro

                          Libre Wave - Freedom respecting instruments and effects
                          My Patreon - HISE tutorials
                          YouTube Channel - Public HISE tutorials

                          ustkU Adam_GA 2 Replies Last reply Reply Quote 3
                          • clevername27C
                            clevername27
                            last edited by

                            Some of us were already quite familiar this one. 😭😭😭

                            1 Reply Last reply Reply Quote 0
                            • ustkU
                              ustk @d.healey
                              last edited by

                              @d-healey Oh boy I miss so much that brit humour 🤣

                              Can't help pressing F5 in the forum...

                              1 Reply Last reply Reply Quote 0
                              • Adam_GA
                                Adam_G @d.healey
                                last edited by

                                @d-healey do you think its possible having this in my project is some how causing my note release issue?

                                d.healeyD 1 Reply Last reply Reply Quote 0
                                • d.healeyD
                                  d.healey @Adam_G
                                  last edited by

                                  @Adam_G No because that issue is happening in a project without any scripting

                                  Libre Wave - Freedom respecting instruments and effects
                                  My Patreon - HISE tutorials
                                  YouTube Channel - Public HISE tutorials

                                  1 Reply Last reply Reply Quote 0
                                  • CasmatC Casmat referenced this topic on
                                  • First post
                                    Last post

                                  11

                                  Online

                                  1.7k

                                  Users

                                  11.9k

                                  Topics

                                  103.6k

                                  Posts