HISE Logo Forum
    • Categories
    • Register
    • Login

    Adding JSON properties to a component via script?

    Scheduled Pinned Locked Moved Scripting
    4 Posts 4 Posters 48 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.
    • E
      ericchesek
      last edited by

      Hello!

      I'm stuck on what seems like a silly issue and I swear I've done it before.

      I am adding a bunch of sliders to a panel in a for loop using Content.addKnob.
      I want each of those knobs to have a custom JSON tag called "idNumber" or something.
      Is there any way to add that "idNumber" JSON property and set it equal to the iterator of the for loop in script? I don't want to manually edit the JSON after the components are created.

      THANKS!

      d.healeyD VirtualVirginV 2 Replies Last reply Reply Quote 0
      • d.healeyD
        d.healey @ericchesek
        last edited by

        @ericchesek you can't add custom properties to a component, either through scripting or by manual editing.

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

        1 Reply Last reply Reply Quote 0
        • VirtualVirginV
          VirtualVirgin @ericchesek
          last edited by VirtualVirgin

          @ericchesek What is it you are trying to achieve? When you are creating the sliders in a loop, are you appending the index number to each in the name?
          Here are some examples of indexing for the ID:

          // a loop to create sliders
          inline function createSliders(stringName, numOfSliders)
          {
          	local sliders = [];
          
          	for (i = 0; i < numOfSliders; i++)
          	{
          		// this appends the index to the slider name: "stringName + i"
          		local slider = Content.addKnob(stringName + i, 50 + i * 125, 50);
          		// this stores the component object inside an array
          		sliders[i] = slider;
          		slider.set("style", "vertical");
          	}
          	return sliders;
          }
          
          // call the function to create the sliders
          const mySliders = createSliders("MySlider", 4);
          // a separate array for the names ("Id")
          const mySlidersIdArray = mySliders.map(function(element){return element.getId();});
          
          Console.print("mySlidersIdArray: " + trace(mySlidersIdArray));
          
          

          So there are multiple ways to use an index as ID to associate with a component.

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

          Christoph HartC 1 Reply Last reply Reply Quote 2
          • Christoph HartC
            Christoph Hart @VirtualVirgin
            last edited by

            @VirtualVirgin Little unrelated tip of the day:

            mySliders.map(function(element){return element.getId();});
            

            can also be written as

            mySliders.map(element => element.getId());
            

            Link Preview Image
            Arrow function expressions - JavaScript | MDN

            An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate limitations in usage:

            favicon

            MDN Web Docs (developer.mozilla.org)

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

            19

            Online

            1.8k

            Users

            12.0k

            Topics

            104.2k

            Posts