Forum

    • Register
    • Login
    • Search
    • Categories

    Lend me your brain

    Scripting Forum
    4
    10
    86
    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.healey
      d.healey last edited by d.healey

      I'm sure this is easy for someone but it's giving me a headache. I want this code to print the numbers 1 to 49... help!

      for (i = 1; i < 50; i++)
      {
          for (j = i+2; j < 50; j++)
          {
              Console.print(/*Magic*/);
          }
      }
      

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

      ustk 1 Reply Last reply Reply Quote 0
      • dustbro
        dustbro last edited by

        Could you add another variable?

        for (i = 1; i < 50; i++)
        {
        
            
            for (j = i+2; j < 50; j++)
            {
                var ii = ii+1;
                Console.print(Math.range(ii, 1, 49));
            }
        }
        

        This will print 1:49.... and then print 49 about 200 more times

        Dan Korneff - Producer / Mixer / Audio Nerd

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

          @dustbro Nice idea 🙂 But I need it to print 1-49 as the loops complete naturally. It's for a progress bar, so having it hang on 49 for a while won't work.

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

          1 Reply Last reply Reply Quote 0
          • Christoph Hart
            Christoph Hart last edited by

            Huh? Why not just

            for (i = 1; i < 50; i++)
            {
                Console.print(i);
                
                for (j = i+2; j < 50; j++)
                {
                   // most important loop in the world...    
                }
            }
            
            1 Reply Last reply Reply Quote 0
            • ustk
              ustk @d.healey last edited by

              @d-healey actually you can't in the second loop, simply because it runs only 47 times...

              for (i = 1; i < 50; i++)
              {
                  var flag = true;
                  
                  for (j = i+2; j < 50; j++)
                  {
                      if (flag){
                          
                          Console.print(i);
                          flag = false;
                      }
                  }
              }
              

              Tired to press F5 in the forum...
              Studio427 Audio - Audio Instruments & FX Plugins for music production. Website - Facebook

              1 Reply Last reply Reply Quote 0
              • dustbro
                dustbro last edited by

                for (i = 1; i < 50; i++)
                {
                
                    
                    for (j = i+2; j < 50; j++)
                    {
                        var ii = ii+1;
                        Console.print(Math.round(ii/23));
                    }
                }
                

                This would give you 0:49 in series

                Dan Korneff - Producer / Mixer / Audio Nerd

                ustk d.healey 2 Replies Last reply Reply Quote 0
                • ustk
                  ustk @dustbro last edited by

                  @dustbro cool solution 😉
                  Just to add an if not 0 and baam…

                  Tired to press F5 in the forum...
                  Studio427 Audio - Audio Instruments & FX Plugins for music production. Website - Facebook

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

                    @dustbro That's doesn't work. I get 00000000000000000000000,111111111111111111111111,222222222222222222 etc.

                    @Christoph-Hart said in Lend me your brain:

                    Huh? Why not just

                    for (i = 1; i < 50; i++)
                    {
                        Console.print(i);
                        
                        for (j = i+2; j < 50; j++)
                        {
                           // most important loop in the world...    
                        }
                    }
                    

                    Ooo well this might work 😱

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

                    1 Reply Last reply Reply Quote 0
                    • Christoph Hart
                      Christoph Hart last edited by

                      OK everybody go home, I found the cleanest solution:

                      
                      inline function getStart()
                      {
                          return Engine.getHostBpm() * Engine.getSamplesForQuarterBeats(800);
                      }
                      
                      inline function getEnd()
                      {
                          return getStart() + 50 * getDelta();
                      }
                      
                      inline function getDelta()
                      {
                          return Engine.getFilterModeList()[2] + Math.min(Engine.getSampleRate(), Engine.getDeviceType().length);
                      }
                      
                      for (i = getStart() + getDelta(); i < getEnd(); i += getDelta())
                      {
                          Console.print((i - getStart()) / getDelta());
                      }
                      
                      ustk 1 Reply Last reply Reply Quote 6
                      • ustk
                        ustk @Christoph Hart last edited by

                        @Christoph-Hart 😂

                        Tired to press F5 in the forum...
                        Studio427 Audio - Audio Instruments & FX Plugins for music production. Website - Facebook

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

                        12
                        Online

                        801
                        Users

                        5.5k
                        Topics

                        51.7k
                        Posts