HISE Logo Forum
    • Categories
    • Register
    • Login

    Can't Access Global Variables in Realtime Scripts?

    Scheduled Pinned Locked Moved Solved Scripting
    13 Posts 4 Posters 350 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.
    • clevername27C
      clevername27
      last edited by

      Can anyone think of why I can't access global variables (declared in the Interface onInit callback) inside the NoteOn callback in Realtime scripts?

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

        @clevername27 Is the real time script before or after the interface script in the chain?

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

        clevername27C 1 Reply Last reply Reply Quote 1
        • clevername27C
          clevername27 @d.healey
          last edited by

          @d-healey Good question - I don't know. Is this where the ordering is indicated?

          03ec8e05-4ccb-4ff0-804a-3afca32d6f6c-image.png

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

            @clevername27 Yes, so the Realtime scripts is after the Interface so it should see the global variable.

            Perhaps try a minimal test project. I avoid using Global variables because they are a maintenance headache. So far I haven't used them in any instrument I've released. That's to say there might be a better way to achieve what you're after, such as Global Cables.

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

            ulrikU A 2 Replies Last reply Reply Quote 1
            • ulrikU
              ulrik @d.healey
              last edited by

              @d-healey said in Can't Access Global Variables in Realtime Scripts?:

              @clevername27 Yes, so the Realtime scripts is after the Interface so it should see the global variable.

              I think it's the opposite, if you have the RealTime Scripts above interface it should work

              Hise Develop branch
              MacOs 15.3.1, Xcode 16.2
              http://musikboden.se

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

                @ulrik That would mean global variables are only accessible in scripts before the script they are declared. That doesn't make sense to me.

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

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

                  This works

                  HiseSnippet 682.3ocyUstaSCCE1tqFQKWDSvCP9YmzzTKLFHMgXrdAUAcqhLl3eSdNtsVywNxwYPEhmJdV38f2.33jrkTVYWh.D4GQ4bK9yeeGe7Xilwii0FDtwAyi3H7cI9yU1YcmQEJzvdH78IinwVtwKy0tyinww7.DFuxqcNvMpiRe99K2kJoJFuvEBcnVv3uUDJrEdGuyaDR4.Z.+.QXor2bmgLspqVpS.7rBoMJhxNgNkuG0kVMBBeq9ABq13aoVdLjyt5f49yzeTkk+ghXwwRtynCxG9QYtQcmIjAiOauFiP35iK14qjsyeDYjHPbt+BF3AoA7JpnLGfqcYPpyM.R0JAo5YPZUhOyHhrEQb34NjgJPPlPAptLTxxEg+FoqFRPY2HjdBefALNufVa0t85dvq01tYyoR8wTo2zi.ja8dgWm1aOIQwrBsxSq1Sa46qZsVyO2rQyuzz6WCMYxRi4VaiVJ4lkF1I4lKqvVpjvi4l08NkJS3mmHvIKRz255QzrLpnThZ0PkvteDO2dfVF3HP22WTVP4bI706G1iZofRgy8A4EwMVgCN3d7SgV8LcqAoGO9DqNBZ1ulh5Cy8Vzl0Yoh6WId+FMB.UrVx2HxHT1VYh5Za68enzQ9SIc+KjK3zuNHQRsKNRvM6KO.vAKHUtCapXgcd4Yi2f4Dsuz4DWWHtJYrvxlsbLVaIXzMB5u.FymtdOR+IS3LaA.qSF7gpNJ8JV92oSrB0zQTqQ7IneaujPe3REFGVckhKc8f3ZttkL61NaGC3yUAoF+.dxC1wYiyC14rfnPJynOhk046lee6TO.lToWW0.t2Dr85fROMTlmCgqSNhwV7WcgBebUK7IUsvMqZgOspEtUUK7YUsvme0E5ts+UIVcX1wFDZz39oiRv39JJzAl1sh9I6lGlD.
                  

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

                  1 Reply Last reply Reply Quote 1
                  • A
                    aaronventure
                    last edited by

                    My current project relies heavily on global variables and there are no issues with them.

                    Declaration order only matters for On Init, as long as you do define checks.

                    1 Reply Last reply Reply Quote 1
                    • A
                      aaronventure @d.healey
                      last edited by

                      @d-healey said in Can't Access Global Variables in Realtime Scripts?:

                      I avoid using Global variables because they are a maintenance headache

                      How so? I find it way easier to use globals than creating connections or calling setAttribute as it allows for a detached architecture where you store data into a global object, then refer to it wherever you need as you tweak and change the instrument. If you suddenly decide to remove a modulator that feeds on control data, you don't have to go back into the interface script to remove setAttribute calls etc. Iterating is super easy and you can always see all the data you're working with in the interface script.

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

                        @aaronventure

                        I haven't used them since 2019 so I might be not remembering some of my objections to them, but the basic problem I have is when I come back to the code after a year I have a variable being used in some part of my project and I have no idea where it was declared - ok not quite no idea, but I have to go hunting.

                        I also like to write in reusable modules, and as much as possible each module should stand by itself. So I can share it with other people or put it in other projects of my own. I don't want each module to be dependent on a set of global variables that might not be in another project.

                        If I had a situation where I absolutely had to have global variables then I would of course use them, but so far I haven't required them and I don't think my code has suffered because of it.

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

                        A 1 Reply Last reply Reply Quote 2
                        • A
                          aaronventure @d.healey
                          last edited by

                          @d-healey said in Can't Access Global Variables in Realtime Scripts?:

                          I haven't used them since 2019 so I might be not remembering some of my objections to them, but the basic problem I have is when I come back to the code after a year I have a variable being used in some part of my project and I have no idea where it was declared - ok not quite no idea, but I have to go hunting.

                          In my case I use them as global namespaces, all the global variables are objects and I store what would normally be variables in a namespace as properties of that global object, so I access them the same way. E.g. I have a global called ControlValue which holds the current values of all controls (I set up a value change broadcaster which stores the value there using the component id), and accessing a control value from anywhere is just ControlValue.controlId.

                          @d-healey said in Can't Access Global Variables in Realtime Scripts?:

                          also like to write in reusable modules, and as much as possible each module should stand by itself. So I can share it with other people or put it in other projects of my own. I don't want each module to be dependent on a set of global variables that might not be in another project.

                          Yeah that's a different approach, no argument there.

                          1 Reply Last reply Reply Quote 1
                          • ulrikU
                            ulrik @d.healey
                            last edited by

                            @d-healey said in Can't Access Global Variables in Realtime Scripts?:

                            @ulrik That would mean global variables are only accessible in scripts before the script they are declared. That doesn't make sense to me.

                            I agree and I tested, both under and over logs the global

                            globalvariable.gif

                            Hise Develop branch
                            MacOs 15.3.1, Xcode 16.2
                            http://musikboden.se

                            clevername27C 1 Reply Last reply Reply Quote 1
                            • clevername27C
                              clevername27 @ulrik
                              last edited by

                              @ulrik Thanks for checking that out. I've narrowed the issue down to arrays.

                              1 Reply Last reply Reply Quote 0
                              • clevername27C clevername27 marked this topic as a question on
                              • clevername27C clevername27 has marked this topic as solved on
                              • First post
                                Last post

                              26

                              Online

                              1.8k

                              Users

                              12.0k

                              Topics

                              104.6k

                              Posts