HISE Logo Forum
    • Categories
    • Register
    • Login

    Random Button & Radio Buttons?

    Scheduled Pinned Locked Moved Scripting
    12 Posts 4 Posters 78 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.
    • ChazroxC
      Chazrox @ILIAM
      last edited by

      @ILIAM I just did this too. lol. Little bit different from @HISEnberg but same outcome I guess.

      This what I got. Mine checks that the power is on before the Randomizer button works.

      inline function onRandomizerControl(component, value)
      {
      
      	local Power = Content.getComponent("Power");
      	local Power = Power.getValue();
      	local RandomNOW = Math.randInt(1, 16);
      	
      	Console.print(RandomNOW);
      
      	if (value == 1 && Power == 1)
      	{
      		Buttons[RandomNOW].setValue(1);
      		
      	}
      };
      Content.getComponent("Randomizer").setControlCallback(onRandomizerControl);
      
      
      HiseSnippet 1272.3ocwX0saaaCElJIpcRqqnYXO.B4hBmgf.I+WbPQv7hSRmwpSLp6xVPPQAiDcLQjIMnnSpaQ.5ixdT1U64YuAajRxVzIVoIzqtJWDPxymNe9vOcNjm1LpOJJhx.F1uYz.Dv3IlcFQ38ZzChIfl6ALdpYKXDGwbRlZ2QCfQQn.fgwxuTNgg0Jf3m+4m1EFBI9nro.fioXezqv8w7rYaW+WwggG.CPuA2Ww5x0a5SIMngzgB9rroKX.z+B34nCgRyVxD7Kvnd.iezrXwt90bcqUpTEWHrT.DV1CUZaT2pc8q3tsavYUbE+UEX7n8CvbJqCGxQQ.iU1kFLpSO5UjDGbLNBeVHRNvCzQ34joOfFFH+IJmEznGNLn83.UDP7VZmE1VNIr8ClsvA3IymE9dV7BNYHTCfFKMM8VdJ54oROWE5MCJYnPoURnzplc7Y3A7rUj74aMaRD6lcgh8IUpjXKXo+1zrAUXAguYe3EnCXhASPTnrq6FNUbcW+E1hGwtUD24RHyoM8JgBYGmwPOGwaP6OfRDCJrV7pqIvjAX2gbtXf.xoyFShAdqs9F1Ny54tPUTKTkzBUYsPU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S9bB.Z0d+36rYXre7sQhUtf+CfziS41
      

      ezgif-75f5e1babf304a.gif

      d.healeyD 1 Reply Last reply Reply Quote 1
      • ILIAMI
        ILIAM
        last edited by

        @Chazrox @HISEnberg Thank you guys, Very nice

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

          @HISEnberg said in Random Button & Radio Buttons?:

          Buttons[i].setValue(i == random ? 1 : 0);

          I thought about this but I didnt think it needed this because they're already radio buttons.

          great excercise!

          Hope all is well brothas!

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

            @Chazrox said in Random Button & Radio Buttons?:

            local Power = Content.getComponent("Power");

            You should create this reference as a const in on init.

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

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

              @d-healey noted 👍

              1 Reply Last reply Reply Quote 0
              • ILIAMI
                ILIAM
                last edited by ILIAM

                How about the below script? I need the power button to get randomized, then the radio buttons follow up
                Is this good?
                @d-healey @HISEnberg @Chazrox

                const var Randomizer = Content.getComponent("Randomizer");
                const var Power = Content.getComponent("Power");
                const var Buttons = Content.getAllComponents("Button");
                
                inline function onRandomizerControl(component, value)
                {
                	local random = Math.randInt(0, Buttons.length);
                	
                	if(!value)
                	return;
                	
                	Power.setValue(Math.randInt(0, 2));
                	Power.changed();
                	
                	if(Power.getValue()==1)
                	{
                	if (value == 1)
                	{
                	    for (i = 0; i < Buttons.length; i++)
                	    {
                	        Buttons[i].setValue(i == random ? 1 : 0);
                			Buttons[i].changed(); // I need this to trigger the callbacks
                
                	    }
                	}	
                	}
                
                
                }
                
                Randomizer.setControlCallback(onRandomizerControl);
                
                d.healeyD ChazroxC 2 Replies Last reply Reply Quote 0
                • d.healeyD
                  d.healey @ILIAM
                  last edited by

                  @ILIAM said in Random Button & Radio Buttons?:

                  if (value == 1)

                  This will always be true

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

                  ILIAMI 1 Reply Last reply Reply Quote 0
                  • ILIAMI
                    ILIAM @d.healey
                    last edited by

                    @d-healey Thanks, David, is this Correct now?

                    	if(Power.getValue()==1)
                    	{
                    	    for (i = 0; i < Buttons.length; i++)
                    	    {
                    	        Buttons[i].setValue(i == random ? 1 : 0);
                    		Buttons[i].changed(); // I need this to trigger the callbacks
                    
                    	    }
                    	}
                    
                    d.healeyD 1 Reply Last reply Reply Quote 0
                    • d.healeyD
                      d.healey @ILIAM
                      last edited by

                      @ILIAM said in Random Button & Radio Buttons?:

                      David, is this Correct now?

                      I don't know, if it does what you want then it is...

                      Buttons[i].setValue(i == random ? 1 : 0);

                      i == random will either be 1 or 0 already, so no need for the ternary operator here.

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

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

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        14

                        Online

                        1.7k

                        Users

                        11.8k

                        Topics

                        102.7k

                        Posts