HISE Logo Forum
    • Categories
    • Register
    • Login

    Help with this noob error please.

    Scheduled Pinned Locked Moved Newbie League
    16 Posts 4 Posters 232 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 @mmprod
      last edited by

      @mmprod https://forum.hise.audio/topic/79/scripting-best-practices

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

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

        @d-healey I have watched your 101 Tutorial 3 times with extensive notes.....but expect me to make alot of mistakes until I dont. ha. Soakin it in...

        hujackusH 1 Reply Last reply Reply Quote 0
        • mmprodM
          mmprod @d.healey
          last edited by

          @d-healey thank you

          For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life.
          John 3:16

          1 Reply Last reply Reply Quote 1
          • hujackusH
            hujackus @Chazrox
            last edited by hujackus

            @Chazrox @d-healey There are a surprising amount of cases to consider when choosing variables and functions. I made a test to show some of the problems that occur when the wrong keywords are used or used at the wrong time.

            Console.clear();
            //testGlobal = undefined; //uncomment to explore what happens
            //testGlobal2 = undefined; //uncomment out to explore what happens
            
            //test(); //doesn't compile (This expression is not a function!)
            testInline();
            
            const TEST_ARRAY = [5];
            const TEST_CONST = 6;
            global testGlobal = 7;
            reg testReg = 8;
            var testVar = 9;
            
            function test(){
            	var t = "";
            	t += TEST_ARRAY[0];
            	t += TEST_ARRAY_2[0];
            	t += TEST_CONST;
            	t += TEST_CONST_2;
            	t += testGlobal;
            	t += testGlobal2;
            	t += testReg;
            	t += testReg2;
            	t += testVar;
            	t += testVar2;
            	Console.print("test():"+t);
            	
            	Console.print(TEST_ARRAY[0]);
            //	Console.print(TEST_ARRAY_2[0]);//doesn't compile (API call with undefined parameter 0)
            	Console.print(TEST_CONST);
            //	Console.print(TEST_CONST_2);//only compiles if TEST_CONST_2 was defined in a prev compile
            	Console.print(testGlobal);
            //	Console.print(testGlobal2); //only compiles if testGlobal2 was defined in a prev compile
             	Console.print(testReg);
            //	Console.print(testReg2);    //doesn't compile (API call with undefined parameter 0)
            	Console.print(testVar);
            //	Console.print(testVar2);    //doesn't compile (API call with undefined parameter 0)
            };
            inline function testInline(){
            	local t = "";
            	t += TEST_ARRAY[0];
            	t += TEST_ARRAY_2[0];
            	t += TEST_CONST;
            	t += TEST_CONST_2;
            	t += testGlobal;
            	t += testGlobal2;
            	t += testReg;
            	t += testReg2;
            	t += testVar;
            	t += testVar2;
            	Console.print("testInline():"+t);
            
            //	Console.print(TEST_ARRAY[0]);  //doesn't compile (API call with undefined parameter 0)
            //	Console.print(TEST_ARRAY_2[0]);//doesn't compile (API call with undefined parameter 0)
            	Console.print(TEST_CONST);
            	Console.print(TEST_CONST_2);
            //	Console.print(testGlobal); //only compiles if testGlobal was defined in a prev compile
            //	Console.print(testGlobal2);//only compiles if testGlobal2 was defined in a prev compile
            //	Console.print(testReg);    //doesn't compile (API call with undefined parameter 0)
            //	Console.print(testReg2);   //doesn't compile (API call with undefined parameter 0)
            //	Console.print(testVar);    //doesn't compile (API call with undefined parameter 0)
            //	Console.print(testVar2);   //doesn't compile (API call with undefined parameter 0)
            };
            
            test();
            testInline();
            
            const TEST_ARRAY_2 = [25];
            const TEST_CONST_2 = 26;
            global testGlobal2 = 27;
            reg testReg2 = 28;
            var testVar2 = 29;
            
            test();
            testInline();
            

            or in snippet form

            HiseSnippet 1126.3oc2W01ahbCD1KIaUg9h5I0OzO5luTnWUOfRBjFE0KgPthZSBJPiZUzIjiWSv5L1q10jbnS4+b+GzN1KaX2vB4DjnJ08KKddwyiGOOKyzIPQYggp.jSgdS7YHmO2s6DodXygDtD09HjyW5dBITyBvQhNbhOILj4gbb13MFAN42DYe96e4PhfHorYhPnKTbJ624i35YR675eiKDGS7X83iRXcsW2lpjMUB0X.Oa3VF4SnuibM6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C0amNdTWXzPJChtTxDlZPmblpkn0kMqMYftLomcw+.OSUVwr1YpxJwJQiHz.UeZTkuYPpO0JAvjzNzYdX5WXMtBxxFRlmGAy00mRSuUy4X0U0weZUcr1p531qpi6rpNVeUcrwi6nYr6CFqUihnMHzIcZY+ThiSKIAp.sUqn+Eg0SCJA
            

            Check out the music of Conway's Game of Life - https://www.youtube.com/@hujackus
            ConwayMatrix - http://hujackus.altervista.org/conwaymatrix/

            ChazroxC 1 Reply Last reply Reply Quote 0
            • hujackusH
              hujackus @mmprod
              last edited by

              @mmprod said in Help with this noob error please.:

              how do they increase performance? Is there a big difference in cpu usage?

              There is a difference when you have a lot of variables. If you use the var keyword for all your variables, when your program references a variable at runtime the program has to search for the location in memory that variable refers to using a dictionary/hash lookup table.

              If you use const or reg, these variables are optimized at compile time to work more like indexing an array, which is much quicker. If I'm wrong, I would like to know a better explanation.

              Check out the music of Conway's Game of Life - https://www.youtube.com/@hujackus
              ConwayMatrix - http://hujackus.altervista.org/conwaymatrix/

              1 Reply Last reply Reply Quote 1
              • ChazroxC
                Chazrox @hujackus
                last edited by

                @hujackus Im not sure how to apply this.

                hujackusH 1 Reply Last reply Reply Quote 0
                • ChazroxC
                  Chazrox
                  last edited by

                  This is why I asked. I've been trying to practice different scripts. My code gets long and things that were working before stop working. My assumption is the order that its placed. Its easy for me to understand writing 1 block of code but as soon as I start writing past that things stop working. Here's an example of painting an image onto a panel. I did the first scope correctly because the image shows up on the panel. I assumed I can just rewrite the same exact code under it and replace the names for the new panels and images and it would work but for some reason the second image>panel is not drawing. Help me understand the Logic. I've been watching hours and hours of scripting videos for HISE and c++ so im up to my nose in it. I feel like I just need a little more insight if you guys can get what im saying and give me a nugget or two. Appreciate you guys!

                  Screenshot 2025-02-09 at 8.10.06 PM.png

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

                    @Chazrox Check your spelling on line 26.

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

                    ChazroxC 1 Reply Last reply Reply Quote 0
                    • ChazroxC
                      Chazrox @d.healey
                      last edited by

                      @d-healey frik. Thank You sir.

                      1 Reply Last reply Reply Quote 0
                      • hujackusH
                        hujackus @Chazrox
                        last edited by

                        @Chazrox said in Help with this noob error please.:

                        Im not sure how to apply this.

                        That's ok. I just made a code example that would have helped me a month ago when I started learning "HISEscript". By uncommenting each line, you can see the differences in behavior for each combination of keywords used.

                        Check out the music of Conway's Game of Life - https://www.youtube.com/@hujackus
                        ConwayMatrix - http://hujackus.altervista.org/conwaymatrix/

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

                        58

                        Online

                        1.7k

                        Users

                        11.7k

                        Topics

                        102.3k

                        Posts