HISE Logo Forum
    • Categories
    • Register
    • Login

    Is it possible to make inline functions that do not require all of the parameter inputs?

    Scheduled Pinned Locked Moved Scripting
    4 Posts 2 Posters 122 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.
    • VirtualVirginV
      VirtualVirgin
      last edited by

      As in

      inline function doSomething(parameter1, parameter2)
      

      then if you write

      doSomething(10)
      

      It could carry on and work without that explicit input of the 2nd parameter?

      I noticed there are methods in the API that work like this (where some parameters are optional) and wondering if this is possible for the inline functions.

      When I test this:

      inline function doSomething(parameter1, parameter2)
      {
      	return parameter1;
      }
      
      const testDS = doSomething(10);
      Console.print(testDS);
      

      I get:

      Inline function call doSomething: parameter amount mismatch: 1 (Expected: 2)
      

      You can listen to my orchestral mockups here:
      https://www.virtualvirgin.net/

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

        @VirtualVirgin It's not possible to have them with optional arguments. What you can do though is just pass one argument that's an object or an array, and within the function check if it contains the thing you're interested in

        inline function myFunc(params)
        {
            if (isDefined(params.myKey1))
                // Do something
        
            if (isDefined(params.myKey1))
                // Do something else.
        }
        

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

        VirtualVirginV 1 Reply Last reply Reply Quote 2
        • VirtualVirginV
          VirtualVirgin @d.healey
          last edited by

          @d-healey Clever!

          You can listen to my orchestral mockups here:
          https://www.virtualvirgin.net/

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

            For more complicated functions you could pass an array of parameters and branch to different functions based on the length of the array.

            For example

            inline function myFunc(params: Array)
            {
                switch (params.length)
                {
                    case 0: return subFunc0();
                    case 1: return subFunc1(params[0]);
                    case 2: return subFunc2(params[0], params[1]);
                    case 3: return subFunc3(params[0], params[1], params[2]);
                }
            }
            

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

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

            18

            Online

            1.8k

            Users

            11.9k

            Topics

            103.9k

            Posts