HISE Logo Forum
    • Categories
    • Register
    • Login

    Randomizer on 3 Grouped buttons, How?

    Scheduled Pinned Locked Moved Scripting
    97 Posts 4 Posters 4.6k 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
      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.3ocsUstSaCCE1tfQzrUzPZO.Q7qVotpTtsIglFqWXpZCnhxPSBgPFGWpEI1YINrUg38bOF6MX63bgFXUEnRq+pmKeG+ki+NG2OTw3QQpPDt7wiC3H7KICFK0iZOhJjndcP3UH6Siz7P6TWsFGPih3tHLdgOYbfKuHJ42u+PKpGUx3SbgPmnDL9WD9B8Du828yBOu8nt7iE9Exdyc6wTx1JOULvmEHNn.J6J5k7CnlzJQP3k55JzpvAZplGgvK1R4NdvH0Ojo4ehHRbgG2XzDM.JTp68TdtFFa7hZOR341O+6NBAUo+jtvBocgWS1W3Jty+jtwqRBXOAQw9AtzrnWyGmdNSid3BzawT5sJY.KTDnmDwvsWP5IgKpgT3JnHsRyEU5WXRaEjgT2vmdEeuPv3NDU21wot8VNN01ohUEK3hHRaeMMz1e7ITuXdj86sO0ody5qWeiy1oXBGQkt8NFBmW7K451J+.kDLptVZ30RKqP5Ijb6gwRlVnj1JYZXCzPkWUVNt5PogSsVEqapXYW3GjYjxi2HHT.UOmbmtOUOpQnoVfW3CYyZmUaGa6JV2lbtylZMhLtSXPapm2Efpq5CXlg9EX8AJM+PY0ZV2XU15VK6GFZ3voFKqXd7voF1LNDNKfUkw9WvCyaN4IB5h6K7V5oI7XockBIpj8jB8gA7L6YO4fxZqFQZFCgT0IRzUxjnsh0ZkDIfhrLIskhRXewsDnu1qCUSyqCTR3XB3gZg4qA2geMrEIU5WlzgGckVEjja1UIz.d7S8mHLA+c3vFa9y5Iah9mIKX9V4F6Q02en2roKK.bgbuoKyDjLRnGWbS3yXSfySdQ0SktqR5KzrQSmuklBeg99+a9lsWsBo6vgbldBYWjr22l2knOCpbjJVKjWBqIBEFgvAw9CfmYXbfIRI2KxnIJYjzo1NFaSmY.W5lX7G3WVvlFabVvl4AQ9TVn5bV5ffYy8xId.NISd.qL7RJXa2Le.fPbZ3f7gGTNmwLsh2.be5XVeNvrwbfYy4.yVyAlsmCLucNv7tYhw7V9Gi0J+zwDvQ+tIKhv3tRJnxRTjn+xdlqWc
        
        1 Reply 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
                            • NatanN
                              Natan @d.healey
                              last edited by

                              @d-healey Yeah, I Guess I'm So Close :)
                              Wait Sir

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

                                @d-healey Haha, That Was A Real Challenge, And Yep This is it :)

                                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);   
                                
                                    if (value == 1)
                                    {
                                       Btns[randomValue].setValue(1);
                                    }      
                                };
                                
                                Content.getComponent("RandIT").setControlCallback(onRandITControl);
                                
                                1 Reply Last reply Reply Quote 1
                                • d.healeyD
                                  d.healey
                                  last edited by

                                  Yeah looks like you got it! Well done!

                                  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 :) Haha Yessir :)
                                    Thanks You Dear David, True Legend :)

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

                                      @Natan You did it, not me. I just nudged you :p

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

                                      NatanN DanHD 2 Replies Last reply Reply Quote 3
                                      • NatanN
                                        Natan @d.healey
                                        last edited by

                                        @d-healey Thanks for the help, You're a great guy :)

                                        1 Reply Last reply Reply Quote 0
                                        • DanHD
                                          DanH @d.healey
                                          last edited by

                                          @d-healey Just trying this out. What if I wanted only one of the buttons to be on at a time? Like a radio group. I can get them to go on and off randomly, but not like a radio group...

                                          DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                                          https://dhplugins.com/ | https://dcbreaks.com/
                                          London, UK

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

                                            @DanH Check out my tabbed interfaces video.

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

                                            DanHD 2 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            15

                                            Online

                                            1.7k

                                            Users

                                            11.8k

                                            Topics

                                            103.2k

                                            Posts