HISE Logo Forum
    • Categories
    • Register
    • Login

    Can't reference inline function parameters in nested function body

    Scheduled Pinned Locked Moved Scripting
    15 Posts 4 Posters 125 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.
    • HISEnbergH
      HISEnberg @JulesV
      last edited by

      @JulesV Just for starters your paint routine shouldn't be placed in an inline function (that is what is producing the error message).

      I am not sure what you are trying to achieve exactly but a better format for applying the LAF here would look like this:

      Content.makeFrontInterface(300, 200);
      
      
      const var CmB = Content.getComponent("CmB"); // combobox reference
      const rounddCBLAF = Content.createLocalLookAndFeel();	
      
      rounddCBLAF.registerFunction("drawComboBox", function(g, obj)
      {
      	// Do Laf stuff here.
      	
      });
      
      Content.getComponent("CmB").setLocalLookAndFeel(rounddCBLAF);
      
      

      Are you trying to make a LAF for your combobox that can be applied to several comboboxes? David has a useful video about this regarding paint routines here:
      https://www.youtube.com/watch?v=jO-KOEcJRKo

      It could look something like this:

      Content.makeFrontInterface(300, 200);
      
      const var CmB = Content.getComponent("CmB");
      const var CmB1 = Content.getComponent("CmB1");
      
      const var comboLaf = Content.createLocalLookAndFeel();
      
      inline function drawComboLaf(g, obj) // One inline function for the LAF
      {
          local a = obj.area;
          local tx = obj.text;
      
          g.setColour(Colours.withAlpha(obj.itemColour1, 0.5));
          g.fillRoundedRectangle([0, 0, a[2], 27], 0.1);
      
          local c1 = (obj.hover || obj.clicked) ? obj.textColour : obj.bgColour;
          g.setColour(c1);
          g.setFont("Arial", (12));
          g.drawAlignedText(tx, [a[0], 0.15 * 27, a[2], 20], "centred");
      
          g.drawAlignedText("label", [a[0], 28, a[2], 20], "centred");
      }
      
      comboLaf.registerFunction("drawComboBox", drawComboLaf); // registerFunction outside of inline function
      
      CmB.setLocalLookAndFeel(comboLaf); // Assign to multiple comboboxes
      CmB1.setLocalLookAndFeel(comboLaf);
      
      d.healeyD 1 Reply Last reply Reply Quote 1
      • d.healeyD
        d.healey @HISEnberg
        last edited by d.healey

        @HISEnberg said in Can't reference inline function parameters in nested function body:

        Just for starters your paint routine shouldn't be placed in an inline function

        If you're using the factory function pattern then it's an acceptable thing to do. Here's an example from Rhapsody.

        However it's probably a good idea to keep laf external to the factory function and just reference the objects.

        Edit: Ah I just read the OP properly, so it's laf and not a panel's paint routine. Carry on.

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

        HISEnbergH 1 Reply Last reply Reply Quote 0
        • HISEnbergH
          HISEnberg @d.healey
          last edited by

          @d-healey Thanks for clarifying that terminology was a bit of a mystery to me, I wasn't aware of the factory method I have some homework to do!

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

            @HISEnberg

            These are good references

            Link Preview Image
            Scripting Best Practices

            This is a collection of useful tricks which will be extended over time. I divided them into two categories: Interface Design and MIDI Processing. Interface d...

            favicon

            Forum (forum.hise.audio)

            Link Preview Image
            HISE | Scripting | HISE Additions

            A summary of all additions made to standard Javascript

            favicon

            (docs.hise.dev)

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

            1 Reply Last reply Reply Quote 1
            • JulesVJ
              JulesV
              last edited by

              @Chazrox @HISEnberg @d-healey
              Thanks for the tips, guys. Very useful.

              My aim was not to print the word "label". I asked how I could integrate the label variable into the ComboBox LAF.

              inline function cbFctry(name, label, x, y, w, h)

              So the label variable is "Types" here.

              alt text

              As previously mentioned, when I use this: g.drawAlignedText(label, [a[0], 28, a[2], 20], "centred");

              I see: Can't reference inline function parameters in nested function body error.

              ChazroxC d.healeyD 2 Replies Last reply Reply Quote 0
              • ChazroxC
                Chazrox @JulesV
                last edited by Chazrox

                @JulesV That was the second option I gave you. Create an object outside of your function and reference it within your function script. I also suggested using 'local' within your function to create the object.

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

                  @JulesV The error there means that label is a parameter of your inline function but it's not in the scope of your laf function which is a different function.

                  What you can do instead is declare a label variable in the namespace, set this from within the inline function and reference it in the laf function.

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

                  ChazroxC JulesVJ 2 Replies Last reply Reply Quote 2
                  • ChazroxC
                    Chazrox @d.healey
                    last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • JulesVJ
                      JulesV @d.healey
                      last edited by

                      @d-healey said in Can't reference inline function parameters in nested function body:

                      What you can do instead is declare a label variable in the namespace, set this from within the inline function and reference it in the laf function.

                      Is this what you mean?

                      HiseSnippet 1297.3ocsV09aSbCF2WaOzxsWDHsuNIq7oKnakjzj9BcHnIsg0Qaoh.EjpPHGeN47hicjOGZi.9592a+gflz9Of83y2kjBgwT0vsIw9wOu7yOuYepVQYooJMxK3oSGyPdeme2oRSR6DBWhNbej2O3eLI0vzXGoVSGSRSYwHOuUenkfWo0PYi+99sHBhjxlSBgNSwori3i3l4TO8AOhKDcHwrmxGs.2MdvgTkrsRnl.3YU+pnwD5Px.1IDKaq3i9URZBx619MquAsQ7Vw0q2bmMojMY6zmzuesMhazXys2o1F6PZr8lrpMQd23fXtQo6ZHFVJxasVp3ocSTWHcF3LdJumfYWTC0ErribGkH1dDsTQsS3h3SKbToHPKmN2sspys8i9Gyi4ynO28cyrMvykXQGn2JWEdqdE3UaQ3UcA3sDH4s.jVyAoa42kp4iMy2whmu0+PIDM6Sf3zhPwwKZk+bM+1JfCoY8QjgrNZXwLIB2nZ0Hb8pUqrafc.gqTCt8nV36goZFbHZ2ZcZuNTidZXYfd4HbYKZRgIa2LBuE7o1FMhvalqh6bGba0ndpVpKwARHNmBwb1LkE7lBi7ZhFK5I.CUt7tkBJYEsz8Vx.2NSV7STSjPPbt5u2RGAbofKY39SjTCWIwEv2BlHrfziIhvWFgmFguHBmTI3Mf0EJJQfGBnovYQhiKrTtnVYfCYoBNRY1PwXl1vYofeczu08wm33MnzaBJUp7E7XSR46B1wtJgwGjXfkIQAAkdmUU1+bNgLbYoDT.Fs87F2t0Q60YAX4bjGY43HkZ3dx3NLlHrh0EtfDqqYC31p7N4tgvxwZxEEmHH5U3eBGDgU898JNHaiJDvb.k0Ifo1Mml4xbhF1kFKQ.lv.9BB3sdH76.q+vUqG59Ic8K3lj8DiSHgVQ4F1H2N0hvUWuYEqG.jqOz7HO39DF0PjCDrvyg7R3ex40eIjft0KsRTqRgkAidFQLgkiNZM.cY1HQ8Zny1aeaFVoBNcHKtB99yfty936lQn2.2xc+H3SyLDFFYT6.t9vx6o4DA32BqUu.3VO5dB9.IK9oftCMPFx4jyq5.aS7sAfO6HXoVlBgPMKtbkcsZOHyA5NNGYi+3eFuTECoHyzb8s+bprjy4jmXMzB8OIOYgTDGaZlYhVhGZW7trOtwrxGk7Dkg8XYHTnjsO9i2pe+ktmMiUqDBldoaaupP+uIXnbxndLcDzo.hzyXDZGd0dr9e9drKdE.0U.s.iJ4gRt4wiYxO2ECn7pNa+3bTArZx5Fey7twEkTHNz102G5Qhx.77qAu4CPO6v8IFRgZ.MNuwAPae1qgKUcM4K4uOKcnQMNi2QiURq88B9hF8RXh2y.yM0N4QvjQjLZ9vzrFQfxuwejeMtqWjkxujSwVcBf4m7eN3V0AGPzljfmykwAc3ZVvyUp3.TQEiUvO.iBAmS88u+u9f6QAex8WvMmp3IBh4pWmZezQ9FP7+J2gYumRlxMSW7QI+ucG6+UHdK+S4FZxxw3JKAiPb9qAFyeYx26eP+9Pex4.bM+Nu3qyyPPPeYCWN3XhQysYSmLYTWHRSYf0kRlvV+4shsRwstpcs0CzkIiyVXSSx2rlcsW9l0J1DxSoZ0qnt5K6ae9lLJ.ljYuSrD7fUXMt1GWXAo3vSwdEkdUU8IBV+5J3FWWAabcEr40UvMutBt00Uvs+xBZeo7dSLpQtxFD53SOHqQnm2ARBjAlksh9GQ5QfY.
                      

                      Screen Shot 2025-06-25 at 13.56.35.png

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

                        @JulesV Yes that's it, it can't be a const though because you can't change the value of a const. You can use a reg instead.

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

                        JulesVJ 1 Reply Last reply Reply Quote 0
                        • JulesVJ
                          JulesV @d.healey
                          last edited by JulesV

                          @d-healey

                          reg variant can only be used inside the inline function. But this time there is another problem, when we want to clone the ComboBox, the last variable used is applied to all ComboBoxes.

                          In the below image, one CB should be "Types", the other one should be "Styles".

                          HiseSnippet 1325.3ocyWk0aabCDlqs2fpsGHAnu1BB8jTfpizZIeDWiDKYqT2Z6XDklT.if.pcozxJJRAtT1VHwu1+rAEnO2WZmYOjjikaRMZ.J00xgywGmY3LTmXzA73Xsg3387Ii3DmuvsyDkMpUDSnHGrGw4qbOhEa4FZJolSFwhi4gDGmkeBRvovJjjwe7nlLISEvmQhPdgVDvOTLTXmQ8jG+SBorMKj+bwv43t9iOHPqZok5w.dV1sJYDKX.qO+XFx1RtjefEGQbtuaC+0BpGtQnueisVOfsNeqdrd8psVX85qu4V0VaKV8MWmWsAw4N6GJrZSGKyxiINqzTGNoSj9bUpAdgHVzUxwI0Hc.KmRtsVFhaQjJoUjPFdRtiJl.Z4jYtskScaes6QhPwT5ybe2MYA5LIl2A5rzUg2xWAd0lGdUmCdK.RNyAoURgz8b6DXDiryVAwym6dfBhl8XPbZdnjxKYIGW2VZfCkc0grA71FXxTIJUuZ0JT+pUKusGNfvUrk1ZXyZzcnAFNrKZ0b0ftsCrlIkJhKTrBsHhmX3g0.g2.9Tas5UnqiJYpB7uIE3iJnichLQC9MtlJ77dvCnszC6papuf5ofbkXHugOUcduwq.xTgcVvf1JgK5yziUPHelh1YgCOgRJTbZuwp.qPqn4PEMaEpj0kKqPunBcRE54UnQk8dSAuBRc.SRG.awbWKKLL2RYhhx.6lB4bDyw.2HtwJ3wPTX3O14oGmxqWAXGUn34hPaTwGB1AmEwE8irvznJddEtDUE9xv6SkckfoSvFR0KGPFbOG1p4g61dNnk51ND43Psdvtpv1btrT4sQsMShUAMKv5BsybEkJFZXmmuqfXUtOpT+JTc2esbJrOiYnLvb.kUYfo1Nil8hLhV9EVjH.SX.eAg2lOA9sO5SRqNTJ8m3UOWXi1UNJhUBEUX4CSWoVEZ0UaTF8Bfb8fxMYA3mwCrLUeIuzoPVD7lcp+qf7pMdEJQsx4VFL5KXxw7LzEfI3I1HReFTK7suMAqARQv.dXY5ilB8T6SeXBgt8Smt86A+fDCQgQB01fquTwcMBlD7akp4mCbzitqTzWwCeNn6RVHK4T1oUSAaC58AfOcKfTKF.gPCOrX4sQs6k3.S2NGhwe52QWnhgTjoZ1eyaRkERcNYIWCPnes7j4RQRYyvsiMJ5.bxkIeRGSOBoUGqs7mpJUN4j5kdz2eod8V3ZXFqQKkbyBWFatX9mDrjZ7vtbSE5YXjdJiPAzqVU18lqJOeSifzCPywnVcfRXe5Ht5lZkPxN0AUvWJCU.q1j522Mq9c9QJh.JTeGWrnJIAwy25k7wKs+Bj9mOXOlkg8Qx.zrZO.s83mAcwS6pTvcOd7.qdTBhGNRqP3638gw7Efmz4aA6MAenM7vPVBMW3wjhYf1uyukcwgz5YHkuOiBd5FPy239RHrX71mYrQduTnB8ZKLbuWp0gdj7Sbnf+ELxEbF028teOgJ4eC58SQ+e9+Gze898vMMzgikL6Uu9AdIsrEfr+qzyG6qqhE1IymK7e1cR9Xg38bOQXChVLFWZAXDOr7I.iY2j6Kc2uWOnKwL.tha6e4Sy01HPWIqP0+Hl0HvroiGOrCDoC3f0UJtDq93rDlrlNuJNG8.c3pvjIXZR1h0v4NYKVKeQHOMvnecPZ8A7theVBE.Spj6UW.tfOLmdspJPJNb00WGDbUUcMA8usBt1sUv52VAabaEb8aqfabaEbyOrf3+rX2wV8vziMDxQmreRcbGm8ULHCLIak72X3cOCD
                          
                          const CmB1 = createCB.cbFctry("CmB1", "Types", 30, 70, 134, 60);
                          const CmB2 = createCB.cbFctry("CmB2", "Styles", 250, 70, 134, 60);
                          
                          
                          // ComboBox 
                          namespace createCB
                          {
                          	
                          
                          //	==================== Create Rounded ComboBox ======================
                          inline function cbFctry(name, label, x, y, w, h)
                          {	
                          	local k = Content.addComboBox(name, x, y);
                          	Content.setPropertiesFromJSON(name,
                          	{
                          		"width": w,
                          		"height": h,
                          
                          	});
                          	
                          	
                          	reg lbl = label;
                          	
                          
                          
                          	local rounddCBLAF = Content.createLocalLookAndFeel();	
                          	rounddCBLAF.registerFunction("drawComboBox", function(g, obj)
                          	{
                          		var a = obj.area;
                          		var tx = obj.text;
                          		
                          
                          				
                          		// BG
                          		g.setColour(Colours.withAlpha(obj.itemColour1, 0.5));
                          		g.fillRoundedRectangle([0, 0, a[2], 27], 0.1);
                          		
                          
                          		// Value
                          		var c1 = (obj.hover || obj.clicked) ? obj.textColour : obj.bgColour;
                          		g.setColour(c1);
                          	    g.setFont("Arial", (12));
                          		g.drawAlignedText(tx, [a[0], 0.15 * 27, a[2], 20], "centred");    
                          		
                          		
                          		// Label - 
                          		g.drawAlignedText(lbl, [a[0], 28, a[2], 20], "centred");	
                          		
                          
                          	});
                          	
                          	k.setLocalLookAndFeel(rounddCBLAF);
                          	
                          	return k;
                          	
                          }
                          	
                          }
                          
                          

                          Screen Shot 2025-06-25 at 14.07.27.png

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

                            @JulesV said in Can't reference inline function parameters in nested function body:

                            reg variant can only be used inside the inline function.

                            Use local within inline functions. reg is for on init and namespaces.

                            However looking at your snippet it seems that the variable isn't visible within the laf function either.

                            So here's a better way to do it. Use the ID of the combo box itself, instead of calling them CmB1 and CmB2 we call it cmb followed by the label we want, e.g. cmbStyles. Then in the laf function we can remove the cmb part to get the label.

                            HiseSnippet 1327.3ocyW8+SabCE2GvUs651Tqz90MYkeJTkQSBI7kxpZIARGa.E0zQmDppxwmSNu3yN5NGfH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pZwL83XIdnYvk1OoOS2GojGpzrWJKCabryi+3o52etyYpniUBAKdtSaNRI9eBXY43ndr3J3SMY5oJBsMuZuX2atWbwiJnoavJnnRtmjqe4Hl7lN.AksqD5auPFq.U01t1OHqqc9VNDGZO66l2LEYYcwCcQ2pU39tSaoNmk3m1aGhlXNFIiYyZHAx1gcJbHd5gJdt6vRFpUirTOZjRZ7CG+aG4OGBqNeCXyIlW5.uDQrxbgWsc4.KbueM6tCoM5LR9tLIls5.i9Z22.4nX+cIw5P+2vkA9c3wL+2nTA9n7seFf+E7jCblzO7geyJEcK8fhAOKc+y++3BW+be3FGpfwBh9pWCwbYsrIf8CW4rey46xDtdRwhh+ytaxskhOz8HtlFNeNtvb3nY6ym.Nlcituvc298gyMlQvkb67yeZt9FBNmRykCNfni4lpoCGG0ExzTFXcojIL8ibVvTwlNtpYrIBzkICrCLkIYSVyL1IaxZ4SB0ozX06nocKL2Y7yrR.NIs2u1CtnOLFW6iaP.k3vUXeGkd0k5Z.qeWAt5cEXi6Jvl2UfqcWAt9cE3F+6.M+GFaOVqhR21fPGbzt1F5NN6JIPEnsZE824A21d.
                            

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

                            JulesVJ 1 Reply Last reply Reply Quote 1
                            • JulesVJ
                              JulesV @d.healey
                              last edited by

                              @d-healey Clever! Thank you!

                              1 Reply Last reply Reply Quote 2
                              • First post
                                Last post

                              32

                              Online

                              1.8k

                              Users

                              12.0k

                              Topics

                              104.4k

                              Posts