HISE Logo Forum
    • Categories
    • Register
    • Login

    Randomizer on 3 Grouped buttons, How?

    Scheduled Pinned Locked Moved Scripting
    97 Posts 4 Posters 4.5k 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.
    • NatanN
      Natan
      last edited by

      Hey Music Lovers
      trying to add a randomizer button, but have no idea how I can pick a button each time?!
      the buttons are in group

      take a look at the snippet:

      HiseSnippet 935.3ocsV8uaaaCDlxILX1qtnEXO.L4ub.ZSksa6FvPP7rSRgwZRMpSK5+UvPQEQDJRAIp15EDf8hr2w7Drsi5GQJotNttsx.1l2cem93G4cjSh0LdRhNF4z7jYQbjy8vSmoLAiBnBEZ79Hm6iOhlX3wjbSCmEQSR3dHGm0dg0fSy0QYOWs2PpjpX7JSHza0BF+khPgox5jA+oPJOj5wOQDVK5mNXLSqFok5TfOqgcQQT14zy3GSsg0.ib13.OgQGO0PM7Djy5C0dylFn+nJO92JRDmJ41AcQSgDka9PszyxXqUzn.gzaR47NAAYYRkJrVtJ7K3iDdhqsWoFOHyAoBQc8vowhnW26ldtyidN0n254z6g3orXQjoxika+LdrBVn7ovRPcZkGKpw+z.ORCQnL6DROmeXLL3ZDcdtq6iHOy0c6eucK6GXoHwP9.Ml7Zpxa3IGS1kTB+LtYjNLRqfAc1pv+V4HqvMzn59EAYclg3Fw2aQw26yiu+hhu+Vkyk7OBkTn3D+TEyHzJhVUvbaFh0xNrR3OBxuLkuc6VWztUSB7H7IcxrQ1cWRWvg03E4+PdxSHeLfZHIA5ToGQP7zj.dLeOBoJBilDIXmCuU4L3KNQ6SLAbxooFCLkHbJKfXfBh81byMyQcY6VWlMCtCcemDq8r4vHpTdJT0z41StRon1r+Xsg+JUmsacQqlstrE41t78mquhDJ4wy0sslNdQ.6nRCOkGWpwkABatuY0yFKW0CKWapEnVMVILuJhWLdwk+nBw01HnfgPnlr5r6WTmMLaMBIfjzDWnqnL5WuWGZIfuA1tw+1XuZukFauug2a+4f8Mi2mZn11LE5.nMQ7XivtD3rO+CP+67lNMw6ySN2nixDphcgv+WBo5SHGry+BusYW+t+6SFfpkE7coXeph0uYPUZH9ChodB8Kh0oQkKwKcZ6UKsOH56VZ6WKsW8W2QZ+7t6vYLZuTI0byCdrm1V3.pmtQGdaWbUhvLq9VpuhSibW5CKWV59P7DggELe91XN7E1A9iluEms2FefuOmYpH653Ce2pdP9WAUdsN0HTmcD0DKrUDGmFNEtpCiCLQo3xDaURCa8b9XW6XqxLkq7xF7evSgyt1wNEN6V5DERYw52yxaHXu8vOkYA3jJ6RTMgayAiIW2BBic2wEEBWp48LlUJdLv84io2Jfo+Jf4oq.lmsBXd9Jf4WWAL+1BwXuO4ejZzg4kIfgIGj0R1w4.EE1kksiD8+TCvZ.K
      
      1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey
        last edited by

        Forget about buttons for the moment. Just make a script that generates a random number between 0 and 2.

        Once you can do that you can go back to your buttons. Put the "random" buttons in an array and use your random number as an array index to enable one of the buttons.

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

        NatanN 1 Reply Last reply Reply Quote 0
        • NatanN
          Natan @d.healey
          last edited by Natan

          @d-healey
          Like connecting it to a slider with ( 0,2) value, and adding randomizing to the slider?
          and change it visible mode to 0, so the randomizer Button changes that knob, and that knobpicks a Button!?
          Good scenario?

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

            @Natan

            Like connecting it to a slider with ( 0,2) value, and adding randomizing to the slider?
            and change it visible mode to 0, so the randomizer Button changes that knob, and that knobpicks a Button!?
            Good scenario?

            No. Just make a script the generates a random number and prints it to the console. It should be about two lines of code. Once you've got that we'll move on to the buttons.

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

            NatanN 1 Reply Last reply Reply Quote 0
            • NatanN
              Natan @d.healey
              last edited by

              @d-healey :( Oh god that makes me wanna hit my head to the wall :( no way it sounds harder now

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

                @Natan Well have a go at it and see how you get on. When you get stuck show me what you've got and we'll go from there.

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

                NatanN 1 Reply Last reply Reply Quote 0
                • NatanN
                  Natan @d.healey
                  last edited by

                  @d-healey said in Randomizer on 3 Grouped buttons, How?:

                  at it and see how you get on. When you get stuck show me what you've got and we'll go from there.

                  Let me focus on it, thanks Sir :)

                  1 Reply Last reply Reply Quote 1
                  • NatanN
                    Natan
                    last edited by

                    I only can do it in this dirty way :(

                    HiseSnippet 1117.3ocyW0saaaCElxILn1YtnEqO.B4Jaft.I61tgUDLO6jTXrkTi5zfcWAiDsMgkHEjnRpaP.1ix.1KxdK1qQeC1NTR1h1Q9mXr.L4Kr442O+cn34vdgBGZTjHDYT9hIATjw2f6OgKG0YDgwQcOFY7T7YjHIMzLUT6IAjnHpKxvXm2oDXTdWTxyW+o1DOB2glKBgtTvbn+JymIyk1q0uv77Nk3Ruf4qY8qZ00Qv6H7Dw.d1AagBHNiIComSTlUBiL16DWlTD1WRjzHjwtsEtS5ORbCO09KYQrq7npE1n9PfREepvyUgXkTTmQLO2dS+eGgfnzKmE1IkEdA9LlKal7b13YIJLy8PmOLJsJ3YqCOqMGdFZva2T38bbemPVfLWiBa6i6xgB0.BTBzgUpsnR+IF2Q.VvkG5SFSOMDVLyiZuwx5klu1xp9aqVQ8AJEQRyqIglefvcaew4lGYN08gTYGgeffCKpcPl9CTdNuWB+04WhEGb+b1VxsWpiJkKjMPTiUYei6aeyUYeyYXpZEF2iwolCh4NRlfaJ3Y+iUdGJ7p4L00WBw1KlVuZkaqVorI7vFXVKQl4QGYZAJTBMuM6a0yzetVN5vHp7RUnpcFQN5vPPCT8pAUsl0UfcSCiyHBeH0sV82lm7zutKaYQX29++X+tjJ1Z1ipPRVcqCwy6J3DlZKVPyK8Ku7mfnUuAPAqnaXRmQY7XBEd6LdygDQMs9wzEp8z4rj8TRQs0MWrkl3lEH9pPJYb1u0xgcg4vp3bXuQ4XZ70xRiGRVVx+D6ExBTTWecUaOVwUV8ZUZsUqXdtPReOuV8J2Vobk6pXtnpACJTWV37ngEpV0YKbUNViG6eEMb5FloFBGwOeOD7x6gn2hyIkczLTv6xYx2GP4KqyBJiRUs.yPEXpLoCySy5vzNVJEbDCZjTFm8VBJAx5M9Qaf66gUaLl46dFSGQXS8sQtunGpuMKv2O18XhjnZvlwC.2DPCkLEsabL8ZXxkz1skwGSiFKEAP4X1dOfz1.p5yyno+RzZxrE+9EsPZQBuNVKOLnOpEFyAsBItLw6BEwAKTP1zf2PK3OK3+3f2TK3e8KOzfu+7AuuGykFlD78wyduVKC+wXsLXE2xmnwanVvTrA8YeAhHFaenEJhbMsKuWHEN3PMmDkSf2rRFYRR+LH5ayxhoZJldLmwP1ug4JGAQv3ugPNhxFNRwBF1IC1duA0fwEEtwdD47yPpFbNSAbnvbCqoFHiGwjSzIkGkAK2T39bbOUOrhwaoBvK7J0iMdyFSuJ9jACnNxbvtK9ze6welbzGDwRFeHLLSHC1igOO1uObqEGJfDNm5oN31nj5.pz0Vp0JloOk6lr3efmLk1p0FYJsmpD4SbBEexI8DN0EAdRhD.S7j6CUFtXFr1b1YpXrErq1GtexmbbTTw2AXuXeZrE9zbK74UagOudK74MagOe+V3yOrReTWM7mikB+zWS.A8NIoGigwI4msf9WLAGGPB
                    
                    1 Reply Last reply Reply Quote 0
                    • d.healeyD
                      d.healey
                      last edited by

                      Make a new file. Generate a random value between 0 and 2 and output it to the console.

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

                      1 Reply Last reply Reply Quote 0
                      • NatanN
                        Natan
                        last edited by Natan

                        @d-healey Is This Good Sir?

                        HiseSnippet 807.3ocsUstSaCCE1tfQzr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ply Last reply Reply Quote 1
                        • d.healeyD
                          d.healey
                          last edited by d.healey

                          It's a good start but there are a few problems.

                          1: I said forget about buttons. Just Console.print() in on init.
                          2: Your function is generating numbers between 0 and 3, you need 0 and 2

                          This is all that was needed

                          const randomValue = Math.randInt(0, 3);
                          Console.print(randomValue);
                          

                          Since you're addicted to buttons let's move on to them :p

                          Add your 4 buttons, put the 3 you want to be random into an array. In the callback for the other button generate a random number between 0 and 2, like you did in your last snippet, and output it to the console.

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

                          NatanN 1 Reply Last reply Reply Quote 0
                          • NatanN
                            Natan @d.healey
                            last edited by

                            @d-healey Haha :) Sir!!!

                            NatanN 1 Reply Last reply Reply Quote 1
                            • NatanN
                              Natan @Natan
                              last edited by

                              @d-healey No Idea,can't do it by myself :)

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

                                @Natan Yes you can, one step at a time. You're not by yourself, I'm here :D

                                Can you create an array?
                                Can you create a button?
                                Can you put a reference to the button into the array?

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

                                NatanN 1 Reply Last reply Reply Quote 1
                                • NatanN
                                  Natan @d.healey
                                  last edited by

                                  @d-healey
                                  I'm still here:

                                  Content.makeFrontInterface(600, 500);
                                  
                                  const randomValue = Math.randInt(0, 3);
                                  Console.print(randomValue);
                                  
                                  
                                  const var Btns = [Content.getComponent("Button3"),
                                                    Content.getComponent("Button2"),
                                                    Content.getComponent("Button1")];
                                  
                                                    
                                                    
                                  inline function onRandITControl(component, value)
                                  {
                                      
                                  
                                  };
                                  
                                  Content.getComponent("RandIT").setControlCallback(onRandITControl);
                                  
                                  1 Reply Last reply Reply Quote 1
                                  • d.healeyD
                                    d.healey
                                    last edited by

                                    Perfect. Now move the randomValue inside the button's callback function, you'll need to use a local variable instead of a const.

                                    You can use the random value as the Btns array index to turn on one of the buttons.

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

                                    NatanN 1 Reply Last reply Reply Quote 0
                                    • NatanN
                                      Natan @d.healey
                                      last edited by

                                      @d-healey is this correct?

                                      Content.makeFrontInterface(600, 500);
                                      
                                      const randomValue = Math.randInt(0, 3);
                                      Console.print(randomValue);
                                      
                                      
                                      const var Btns = [Content.getComponent("Button3"),
                                                        Content.getComponent("Button2"),
                                                        Content.getComponent("Button1")];
                                      
                                                        
                                      
                                      inline function onRandITControl(component, value)
                                      {
                                          local idx = buttons.indexOf(component);
                                      
                                          
                                      };
                                      
                                      Content.getComponent("RandIT").setControlCallback(onRandITControl);
                                      
                                      
                                      
                                      d.healeyD 1 Reply Last reply Reply Quote 0
                                      • d.healeyD
                                        d.healey @Natan
                                        last edited by

                                        @Natan Not even close :p

                                        Move the randomValue stuff inside the button's callback. You'll need to use a local variable instead of a const. You can delete the Console.print() we don't need that now.

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

                                        NatanN 1 Reply Last reply Reply Quote 0
                                        • NatanN
                                          Natan @d.healey
                                          last edited by

                                          @d-healey Lol

                                          Content.makeFrontInterface(600, 500);
                                          
                                          
                                          
                                          
                                          const var Btns = [Content.getComponent("Button3"),
                                                            Content.getComponent("Button2"),
                                                            Content.getComponent("Button1")];
                                          
                                                            
                                          
                                          inline function onRandITControl(component, value)
                                          {
                                          local randomValue = Math.randInt(0, 3);
                                          Console.print(randomValue);    
                                          
                                          };
                                          
                                          Content.getComponent("RandIT").setControlCallback(onRandITControl);
                                          
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • d.healeyD
                                            d.healey
                                            last edited by

                                            Now we're getting somewhere!

                                            We don't need Console.print() any more, that was just for testing the random value which we know works now.

                                            Do you know how to turn a button on or off by changing its value?

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

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

                                            48

                                            Online

                                            1.7k

                                            Users

                                            11.7k

                                            Topics

                                            101.9k

                                            Posts