• Products
    • Isadora
    • Get It
    • ADD-ONS
    • IzzyCast
    • Get It
  • Forum
  • Help
  • Werkstatt
  • Newsletter
  • Impressum
  • Dsgvo
  • Press
  • Isadora
  • Get It
  • ADD-ONS
  • IzzyCast
  • Get It
  • Press
  • Dsgvo
  • Impressum

Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags

    [ANSWERED] Javascript help

    Troubleshooting and Bug Reports
    4
    9
    891
    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.
    • Skulpture
      Skulpture Izzy Guru last edited by Juriaan

      Hi.

      I want to create a javascript that will look at 5 incoming float values. If all 5 float values are 1 then output 1. If not then always output a 0.

      I have been using chatGPT but with no success. 

      This is what I have so far. Any help appreciated.

      // Function to continuously check the input values and update the output
      function continuouslyCheckInput(iz_input1, iz_input2, iz_input3, iz_input4, iz_input5) {
          // Get input values
          const inputValues = [
              parseFloat(iz_input1),
              parseFloat(iz_input2),
              parseFloat(iz_input3),
              parseFloat(iz_input4),
              parseFloat(iz_input5)
          ];

          // Check if all values are 1
          const outputValue = inputValues.every(value => value === 1) ? 1.0 : 0.0; // Ensure float values are returned
          
          // Send the output value to the output channel
          SendOutlets(outputValue);
      }

      Graham Thorne | www.grahamthorne.co.uk
      RIG 1: Custom-built PC: Windows 11. Ryzen 7 7700X, RTX3080, 32G DDR5 RAM. 2 x m.2.
      RIG 2: Laptop Dell G15: Windows 11, Intel i9 12th Gen. RTX3070ti, 16G RAM (DDR5), 2 x NVME M.2 SSD.
      RIG 3: Apple Laptop: rMBP i7, 8gig RAM 256 SSD, HD, OS X 10.12.12

      DusX bonemap 2 Replies Last reply Reply Quote 0
      • DusX
        DusX Tech Staff @Skulpture last edited by DusX

        @skulpture

        try this:

        // You can customize the names of your inputs and outputs using comments
        // like the ones below. Click the "Help" button and read "Customizing
        // Input and Output Names" to learn more.
        // iz_input 1 "input 1"
        // iz_output 1 "output 1"
        function checkValues(vals) {
            // Convert arguments object to a real array
            const values = Array.from(vals);
            //print(values);
        
        // Check if all values in the array are exactly 1
        const allOnes = values.every(value => value === 1);
        //print(allOnes);
        
        // Return 1 if all values are 1, otherwise return 0
        return allOnes ? 1 : 0;
        

        }
        function main()
        {
        return checkValues(arguments);
        }

        Troikatronix Technical Support

        • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
        • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
        • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

        Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

        Skulpture 1 Reply Last reply Reply Quote 1
        • Skulpture
          Skulpture Izzy Guru @DusX last edited by

          @dusx thanks for helping. I get anther error, unfortunately. 

          Graham Thorne | www.grahamthorne.co.uk
          RIG 1: Custom-built PC: Windows 11. Ryzen 7 7700X, RTX3080, 32G DDR5 RAM. 2 x m.2.
          RIG 2: Laptop Dell G15: Windows 11, Intel i9 12th Gen. RTX3070ti, 16G RAM (DDR5), 2 x NVME M.2 SSD.
          RIG 3: Apple Laptop: rMBP i7, 8gig RAM 256 SSD, HD, OS X 10.12.12

          1 Reply Last reply Reply Quote 0
          • bonemap
            bonemap Izzy Guru @Skulpture last edited by bonemap

            @skulpture

            Hi,

            Here is a non-javascript solution if that is of use. I modified a macro from a current patch I am working on.

            It returns 1 if all inputs are 1 otherwise another value in any input returns a 0.

            trigger-on-data-set-1.iua3


            Best Wishes,

            Russell

            http://bonemap.com | Australia
            Izzy STD 4.2 | USB 3.6 | + Beta
            MBP 16” 2019 2.4 GHz Intel i9 64GB AMD Radeon Pro 5500 8 GB 4TB SSD | 14.5 Sonoma
            Mac Studio 2023 M2 Ultra 128GB | OSX 15.3 Sequoia
            A range of deployable older Macs

            1 Reply Last reply Reply Quote 0
            • Juriaan
              Juriaan Tech Staff last edited by Juriaan

              Hi all!

              // You can customize the names of your inputs and outputs using comments

              // like the ones below. Click the "Help" button and read "Customizing

              // Input and Output Names" to learn more.

              // iz_input 1 "input 1"

              // iz_output 1 "all true"

              function main()

              {

              for (let i = 0; i < arguments.length; i++) {

                  var value = arguments[i]

                  

                  if (value == 0) {

                  return 0

                  }

              }

              return 1

              }

              Isadora 3.1.1, Dell XPS 17 9710, Windows 10
              Interactive Performance Designer, Freelance Artist, Scenographer, Lighting Designer, TroikaTronix Community moderator
              Always in for chatting about interaction in space / performance design. Drop me an email at hello@juriaan.me

              bonemap 1 Reply Last reply Reply Quote 1
              • Juriaan
                Juriaan Tech Staff last edited by

                The above code is something that I use in my projects; really a simple loop that when it finds a 0 automatically breaks and returns a 0

                If all passes it will return a 1.

                Please be aware that you need to make that your values are either 0 or 1

                Isadora 3.1.1, Dell XPS 17 9710, Windows 10
                Interactive Performance Designer, Freelance Artist, Scenographer, Lighting Designer, TroikaTronix Community moderator
                Always in for chatting about interaction in space / performance design. Drop me an email at hello@juriaan.me

                1 Reply Last reply Reply Quote 1
                • bonemap
                  bonemap Izzy Guru @Juriaan last edited by

                  @juriaan

                  That works!

                  http://bonemap.com | Australia
                  Izzy STD 4.2 | USB 3.6 | + Beta
                  MBP 16” 2019 2.4 GHz Intel i9 64GB AMD Radeon Pro 5500 8 GB 4TB SSD | 14.5 Sonoma
                  Mac Studio 2023 M2 Ultra 128GB | OSX 15.3 Sequoia
                  A range of deployable older Macs

                  DusX 1 Reply Last reply Reply Quote 0
                  • DusX
                    DusX Tech Staff @bonemap last edited by

                    The code block replaced '=>' with '=>'
                    Don't know why, but it won't let me fix it.

                    Troikatronix Technical Support

                    • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
                    • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
                    • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

                    Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

                    1 Reply Last reply Reply Quote 0
                    • Skulpture
                      Skulpture Izzy Guru last edited by

                      @juriaan said:

                      // You can customize the names of your inputs and outputs using comments // like the ones below. Click the "Help" button and read "Customizing // Input and Output Names" to learn more. // iz_input 1 "input 1" // iz_output 1 "all true" function main() { for (let i = 0; i < arguments.length; i++) {     var value = arguments[i]          if (value == 0) {     return 0     } }
                      return 1
                      

                      }

                       Yup this is perfect! Thank you!

                      Graham Thorne | www.grahamthorne.co.uk
                      RIG 1: Custom-built PC: Windows 11. Ryzen 7 7700X, RTX3080, 32G DDR5 RAM. 2 x m.2.
                      RIG 2: Laptop Dell G15: Windows 11, Intel i9 12th Gen. RTX3070ti, 16G RAM (DDR5), 2 x NVME M.2 SSD.
                      RIG 3: Apple Laptop: rMBP i7, 8gig RAM 256 SSD, HD, OS X 10.12.12

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