HISE Logo Forum
    • Categories
    • Register
    • Login

    indexOf Bug?

    Scheduled Pinned Locked Moved Scripting
    7 Posts 3 Posters 165 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.
    • Oli UllmannO
      Oli Ullmann
      last edited by

      Shouldn't the code in this snippet print out the index of “Button1”?
      I only get -1

      const buttons = Content.getAllComponents("Button");
      
      Console.print(buttons.indexOf(Button1, 0, 0));
      

      Snippet:

      HiseSnippet 815.3ocsVstaSCCE1tqYhVtHlDO.QSBoVzzTRWnqUSH55MnB5VEcLw+FtNNqVKwNJwYrJDuP7Tvy.OI7a9CXmj0Kzns0NQpTUN9b9N9SemiONCB3XRXHO..KdxDeB.9HsgSXhwsFinLPu1.3C0NLH.M4DRn.zbhOJLjXCfvMdiJ.Xg7f3me85lHWDCSlsD.bJmhIum5QEyVcPi2Qcc6hrImP8lKZqF8vbVKtKORRlMzL.9H7EnyIGgTgkSC7VT3X.7EZlUq3ruo0H4u5UpZgF4TynloY85HRcGREaqp3ZHCKC.byN1TAOXn.IHgxj1jaOY3X9WXIavozP5HWhxvDLTtyIKCZMl5ZO3ZkID.f4GLSm1HQmdlVepMc55yzqmF6PeFh4EMXtahRlq.kfyQo7ITZKsg3.puXlmj5WOlfD3fj0l4oRRrfbOGp0hKifI10CcAoafzXJhRUML1QW9W4CJVTVeBE5ihDB4K5uR+ZXmSDG551h64yYR6vRa2LNlsUfjAExcI65GPYhRof2kxrIWcrSoj.M2QWtKFkKefSDCKnblNmcDWPNlUpbwuVrPwuUT+ec43joOEoB3ttjfLcqZ5BtIfkXQdiHA6neIxMhLMPoHuXkay6VkCmnQyEHm0iQEG6SRs6xcsUUD06KWmAohrpILkgxPEw06mjVuSDQ.UljBZoJJHl9yeXDrBvqb+fu28CtUFv+Xu1HAR02mJHRQxmDHnpZArM4R4jljSAEzZSBuPv8iUrzdR462AM6poa4ObaLYpQiO2.rRYpxRYRC98DQXExxdYjketxYwJir763AwKM+PN4haG4hDKNNSMnO0g7jxByPTyIXgTwj4uHXElwYbiy3tqTbKsATAdb1bLWFbT1F8+fio2L7XsNNNDrXFAyq08Sq60.2x1+AdjfxNuORDPkEZsih7FJuAESj6NiQbCU06bpllDaCksRAFRX1wF+Q9j5zTYCScZdsSfGBGvOCmb.Vc2yChWQxIV7cyEz5qr0yXnim7pvyv3ES0R.qrt.2acAZst.e45Br55Bb+0EXsaGn5KUNLRv8RN1..8GzIdNKD1ggjcfwcqf+hUq+NB
      
      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @Oli Ullmann
        last edited by d.healey

        @Oli-Ullmann You haven't declared "Button1". Your array contains objects, not component names.

        So this would work

        Console.print(buttons.indexOf(buttons[0]));
        

        But this wouldn't

        Console.print(buttons.indexOf("Button1"));
        

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

        Oli UllmannO 1 Reply Last reply Reply Quote 1
        • Oli UllmannO
          Oli Ullmann @d.healey
          last edited by

          @d-healey
          Hey David,
          Thanks, that makes sense!

          Is there a way to find a specific object within an array, or do I have to declare it with a variable first?

          ustkU 1 Reply Last reply Reply Quote 0
          • ustkU
            ustk @Oli Ullmann
            last edited by

            @Oli-Ullmann you could check for the id of that object

            Hise made me an F5 dude, browser just suffers...

            Oli UllmannO 1 Reply Last reply Reply Quote 1
            • Oli UllmannO
              Oli Ullmann @ustk
              last edited by

              @ustk
              But how?

              ustkU 1 Reply Last reply Reply Quote 0
              • ustkU
                ustk @Oli Ullmann
                last edited by

                @Oli-Ullmann

                 const buttons = Content.getAllComponents("Button");
                 
                 for (b in buttons)
                 {
                	 if (b.getId() == "Button1")
                	 	Console.print(buttons.indexOf(b));
                 }
                

                Hise made me an F5 dude, browser just suffers...

                Oli UllmannO 1 Reply Last reply Reply Quote 2
                • Oli UllmannO
                  Oli Ullmann @ustk
                  last edited by

                  @ustk
                  Great, I didn't think of that. Thank you very much! :-)

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

                  23

                  Online

                  1.9k

                  Users

                  12.4k

                  Topics

                  107.9k

                  Posts