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.
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.
-
@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
-
@ulrik That would mean global variables are only accessible in scripts before the script they are declared. That doesn't make sense to me.
-
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.
-
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.
-
@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.
-
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.
-
@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 justControlValue.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.
-
@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
-
@ulrik Thanks for checking that out. I've narrowed the issue down to arrays.
-
-