HISE Logo Forum
    • Categories
    • Register
    • Login

    Random Button & Radio Buttons?

    Scheduled Pinned Locked Moved Scripting
    12 Posts 4 Posters 76 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 @ILIAM
      last edited by

      @ILIAM You were very close. Give this a try.

      HiseSnippet 1184.3ocwX0uaaaCDmxIpawqoHEXO.B4ubVKBrh+JYcA0MNIcFqNwntKXAEEELTTwDQhzfhJstEcXOZ6QZuAaGkjsjar1ZsVbHBfyc79c7mNdG+puTPnAABIxn7qFOhhLtu4fwb0vNCwLNp6gHiGX1CGnnRqXUGLdDNHf5fLLV44ZEFqsJJp8WO8.rGlSnopPnyDLB8ELelJUa+1+Byy6XrC8UL+LVWucWhf2Q3IBA9rhYUzHL4J7kzSvZyJYh9YbvPjwOXtmas81sYUbMmcITBotaiVMqisqWqAltWMWrMg1pwNDfj26HGlRHGnvJZ.xX0CDNiGLT7Nd7.bFKfcgGUKXiF.ibr5iEdN5OQsVTmgLOm9SBTAHvK8SCaqDG19dydLG1T8oguMh5vJEQ1.nQoYo2JyPO6rzqZF5MGJYjgRqFSoGZNfHYiTo8n4y2Y1kCyltXXdJKUhsEU52KY1Q.VvUa6iuhdrDDlhnR8pUerUipU25IkKCyUAJqqwRqWh4NBe1Gfjj8slf9RppivejfCBU1L0jMmE6AgJEHLKvm44MEaPkMisIBHi6w3TK2PNQwDbKAO0yZGHEdUHSf9XXD7Boasd4OVdMOAA6YIirFFsdX0vs0RvGWE3iJgGa6Q4WpFBC05ksfFy0pRjSr1eeK6shU9w3ezMWgzpBC7W0mXwr9oOyMftG8nsRsNCPcKw3Wydy1AT0Y5gQ6q8mvxmZYa8iVPvNE1mh+W3G3u0Km9wq8PR.nC1y6BnxoxbBNZeAsLwuSDJ5o7JaoiQk+TYqOuKW241Wh+7nx41stxV9uArBOz+BpbxTzDCgr2YKILyujHaEKIN4IigBdWNSc5HJOu5XTRFGT9rQBq.SUQEOOHo3IdJBwfZj0LiErQQTFTbuIqxg9JfuSwfWqXvqWL3MJF7lECdqhAe2hAeuECd4IoMUKHd6BhOShmwhfuVAG+5EDeiBhedIe+Z2CwJrd+yj0Bf0GFQkJldoGiCoWCmdId2z0LOjFbkRLB1Xc5dSf2ycbuuY5hun2mdJGd6wSEZ+g1ui4nFNUwe751CorKGl4zRcaGful1k2WRgk30aUyB5I7gQGKAOYThxwvBh5SY7BJVx0VLY2jS4c7XjqzVgxP5u4KXMt2m8TbiyJLKiQmeCFedaI1gIdtTDNJ6wC+5nvNYov4suKnPsrTfcmPg5YnveJuSnPibyENu8RhBMyMWXoQgV4lKrznvt4lKrznvd4lKvtsoPl8QyKYX4wA6byFVdbXmbSGVdbnVd4C.gVVbndd4CKQNzHu7gkHGZlW9Pg3vMeWgML6IbB8vpYelC8iAkzAbQuYdaA86GvCXpwY87+au8wWJEenYelhLb9brzb3HbrvaCNl7hQqadjqKknRI3plG+a2NOOD5khPEieYOrRxfrDySB8GHBkDJL5bN0SeQa3LhZnQxU0x5Hv.J2IR3ugVRm1ZYijNsmzIxGSjh2RhOQt9Mo91HM.m3Que2Zl8zxVo2iYZb1GN75aIjYc0M.tyhBr1hBr9hBrwhBr4hBr0hBb2+af56V7rPkvOtrAg50+nn6MYXbTzkOhxVQ+CjQxFdK
      
      Content.makeFrontInterface(400, 500);
      
      const var Randomizer = Content.getComponent("Randomizer");
      
      const var Buttons = Content.getAllComponents("Button");
      
      inline function onRandomizerControl(component, value)
      {
      	local random = Math.randInt(0, Buttons.length);
      
          if (value == 1)
          {
              for (i = 0; i < Buttons.length; i++)
              {
                  Buttons[i].setValue(i == random ? 1 : 0);
              }
          }
      }
      
      Randomizer.setControlCallback(onRandomizerControl);
      

      Inside the for loo, the Buttons[i].setValue(i == random ? 1 : 0); basically breaks down as this

      for (i = 0; i < Buttons.length; i++)
      {
          if (i == random)
          {
              Buttons[i].setValue(1);
          }
          else
          {
              Buttons[i].setValue(0);
          }
      }
      
      ChazroxC 1 Reply Last reply Reply Quote 1
      • 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.xoyFShAdqs9F1Ny54tPUTKTkzBUYsPUQKTU0B0VZgplVn1VKTdt5ASO0gmdxCO8zGd5IP7zSg3IjHuU7sIlDhIHmtCI9bLk3PIuFRBn8we.wj3YzvB9iAug3Kxvgn0s+nssUH0GFde+d9FVG+eosGKeeExLHw4GdzuKLpEj2aSlXBQVkBda33UUZmskvUQzPzlCXXwBSPHyzXg65THliN6riimyye9XWJFsts0GssrRSnb5DfucynwDwS5AgKt195WXO6eRYgm0VWBLMH0.FFdlnHTgYD.kLSI.eHkiNhTPFEsru114lK0s6LWK8kEhXybYYER1cAr.YX+yPLk8vXCEUAltzhY9kVTq74mDcTLjRZRv7iFfH4UODjFREkgVMkUBS4wEgdZZQnjsG.VTq4wlwadfXBqdVAv8.rkYpPeLbSiGJzhS77iLzvyklO3kmO3UlO3U0Ors0744ZyG7s0Ct8X4h6bh2aNwWbNwW5guwMAa44z2UlS7UmA9eq4dPNTdv0zjGhDJCPLNVlqxXOzkhqMjbLVKy8PQWvoC.Fe+jD1hC1+Yyu79I4V9zw0GMYveNp9U3.durLOGVuGBedOt5L.EWYkqqdhYVUAE+AHJ9q9Gtg+9zo2xeMqGAuD0jzlgD0djGGGG0h1W3cHS7lLVBQfhj0xaR7JDjQjVnxvGeOxW9d0TsiTGbivwI2hdmTmACvzWxnCGndeuGFEJpRgSp+0fBkTo.9qBEJqPg+h8UgBUxUKbR8EDEplqVXgQgsxUKrvnPsb0BKLJrctZA7WZJnTaNOwvhiCd4pFVbbnXtxgEGGJkmdPPnEEGJmmdXAxgJ4oGVfbnZd5g4hC2tQgOyrEMXXHjOceKkc2McAwMNmpYgxFBRhv7Qpu4a1LyUteMy7t6058ktqZ1Fy86Ma9tzL3q3nmeo4aZqg+Ny861E4yyH6JlG7G2Yef++gJulNjiIm2BxYXgRx7vg86PGx7QBlPHnPYWALVRdX9jwtiucQGDIHdv+JdRWzSN1HcQuwKB5C8Yz24mba.Yin+l3YDbhD2zdKyVxwNd29598Eml8c99S+ptEvh5Brjt.KqKvJ5Brpt.2RWf097.kW13mGxo8S9bB.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

                          25

                          Online

                          1.7k

                          Users

                          11.8k

                          Topics

                          102.7k

                          Posts