Print array index



  • Not sure what I'm doing wrong here... trying to print the index of an array to the console but getting the wrong number.
    Here's what I'm doing:

    const var Knob3 = Content.getComponent("Knob3");
    const var Knob1 = Content.getComponent("Knob1");
    const var Knob2 = Content.getComponent("Knob2");
    
    const var Knobs = [ Content.getComponent("Knob3"),
                        Content.getComponent("Knob1"),
                        Content.getComponent("Knob2")];
    var a = Knobs.indexOf("Knob2");
                        
    Console.print(a);
    

    I'm expecting to see 2, but the console outputs -1


  • administrators

    The array stores a reference to the UI, not the String name.

    var a = Knobs.indexOf(Knob2);
    

    should yield 2.



  • @christoph-hart thank you!
    More noob questions on the way.... although I'm trying to figure them out on my own 🙂



  • This post is deleted!


  • I'm trying to get familiar with using an index to show/hide controls, but it's not clicking in my brain yet... Also my first time using radiogroups.
    As a test, I have a simple instrument with 2 samplers. The user interface has buttons (in radiogroup) to select each sampler, and a second set of buttons (in separate radiogroup) to show/hide controls of the samplers.

    0_1534634825552_simp.png

    All buttons have been put into associated arrays, I've created a Callback function for the buttons, and I'm using the onControl section to show/hide content.

    What I'm attempting to do is use the index of my SamplerSelectButtonArray to show/hide knobs in the GainSliderArray or PanSliderArray.
    Any thoughts are appreciated.

    Content.makeFrontInterface(500, 300);
    
    const var Sampler = Content.getComponent("Sampler");
    const var Sampler2 = Content.getComponent("Sampler2");
    const var Gain = Content.getComponent("Gain");
    const var Pan = Content.getComponent("Pan");
    const var SamplerGain = Content.getComponent("SamplerGain");
    const var SamplerPan = Content.getComponent("SamplerPan");
    const var Sampler2Gain = Content.getComponent("Sampler2Gain");
    const var Sampler2Pan = Content.getComponent("Sampler2Pan");
    
    //create arrays
    
    const var SamplerSelectButtonArray =      [
                                            Content.getComponent("Sampler"),
                                            Content.getComponent("Sampler2")
                                        ];
                                   
    const var ControlSelectButtonArray = [
                                            Content.getComponent("Gain"),
                                            Content.getComponent("Pan")
                                        ];
                                   
    const var GainSliderArray =         [
                                            Content.getComponent("SamplerGain"),
                                            Content.getComponent("Sampler2Gain")
                                        ];
                                        
    const var PanSliderArray =         [
                                            Content.getComponent("SamplerPan"),
                                            Content.getComponent("Sampler2Pan")
                                        ];
                                        
                               
    inline function buttonCallback(component, value)
    {
        if(value)
        {
            local index = SamplerSelectButtonArray.indexOf(component);
                var y = ControlSelectButtonArray.indexOf(component);
                
            Console.print(index);
            Console.print(y);
        }
    }
    
    
    for(a in SamplerSelectButtonArray)
        a.setControlCallback(buttonCallback);
        
    for(a in ControlSelectButtonArray)
        a.setControlCallback(buttonCallback);
    function onNoteOn()
    {
    	
    }
    function onNoteOff()
    {
    	
    }
    function onController()
    {
    	
    }
    function onTimer()
    {
    	
    }
    function onControl(number, value)
    {
    	 if(number == Gain)
        {
            GainSliderArray.showControl(index);
        }
        else if (number == Pan)
        {
            PanSliderArray.showControl(index);
        }
    }
    


  • @dustbro

    This line var y = ControlSelectButtonArray.indexOf(component); You should use local rather than var.

    This line GainSliderArray.showControl(index); Where is index coming from?



  • @d-healey said in Print array index:

    This line GainSliderArray.showControl(index); Where is index coming from?

    I thought:

    local index = SamplerSelectButtonArray.indexOf(component);
    

    Is that only available in my buttonCallback function?



  • @dustbro Ya, that's why it's local 🙂 post a HISE snippet, I think I will be able to help you more then.



  • HiseSnippet 1609.3oc6ZE0aaaCDVJIrK1qtXcnOrWFfPwFfKVWpsSZ6FJFpSbZ5BVSiWbZ2vJ1JXjocHpLo.EsW7JJv90rm2Og9Sp+C1NRIYQ4X6Hk5zs0Y8PPHOdG+3cGO9QlzTvcIAAbgkcgCG5SrruLp0Pl73FGioLqc21xdUjjDHcpYs0PebP.osks8xOTI0tvJV5u2b+svdXlKIoKKqmxotjGQ6QkI81r92Q871A2lbHsmwn2n9ttbVCtGuOfjkQUr7wtu.2k7XrZXKgrrQOnMUxEsjX.NV1qrEu8vVGy+UV33eJMfdjGQ0npUKvPgcuC2qsBwpdsZbL0qcy3Ubfkk8kZlr9WNb8eMzdz1zQ8m3G9Hs.mDML8G1KMK3U0DdUxN7rMf2Jgv6pnVtBpuLQhBae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DSgGbftTy3Z8l6qyUNT.7l.Ogof8YDvsKMWiMD7ffNvxQaq.SQM6K5p7UI8b.Y.QDjtuG2uGD5YLhmh9is5f9mDPTgZp6dXofdh4n0yRkCw5v8mipswZo+FrO7iNeg5W+5F51gpTM+pTK+prd9UYi7qxsyuJ2I+pb2boRXh1dX+I91keP1X0BpCkpIdFibKZWCSq5wbW8njOMVMdbz+y8xmu6N2Y4rA2y3wYKDiwVTUz4ArAPwJnmvCa1lzA22SNpWSPtGmw8OlyntoqL.6z61kHLg9DWOaJkPgojdtV8Cf6EhCLJs8Y0eDbocrHcAub4JplcWwrBWeBJDtNph8NuePWX4+2SWXVttXFsNvrKj+KONeYjtTuihNx+TP8.deIPyH9ndDvGnEvAxkXxJXIESiv1UheMfVDVaci+B9hDVMlBgRX0XgVtwlBVaQ+t9Fv1KSXpSNzrf8.xIdlozA.SKEjfCzrBzA0dpCgVQ44f9ZgGPBqvDhmoRmZOpaSN3Lg8QphNn6kCtmF2288Ixmyvasf74BxmKHetf74BxmKHetf74BxmKHeNuIe9tXQ2C6J3O2M7uUkZouptG.AL8+faEP6oZ6TM9OOkJX0CN264ttpcUeIDtlrF0xsFqmaM1H2Zb6bqwcxsF2M2Z7UyPCEIiM6K48BqwZY82.KOFiSB
    


  • Almost got it figured out.... 😀


Log in to reply
 

0
Online

306
Users

848
Topics

5.5k
Posts

Looks like your connection to Forum was lost, please wait while we try to reconnect.