Trouble with variable in Atom-hydra

Hi folks
I don't know if someone can help me here, sorry if my question is OT but i can't resolve this issue and is just some nigth that give me some pain.
I have a troble using Tidal and Atom-Hydra together in Pulsar.
Tidal is ok, and the OSc message is right config as documentation.
My problem is in Atom-hydra: every variable i define console throw an error like

ERROR ReferenceError: VARIABLE_NAME is not defined
    at Array.eval (eval at _eval (main.js:40), <anonymous>:1:11)
    at Output.typedArg.value (/Users/--/…mat-arguments.js:68)
    at Output.draw (eval at compile (/Users/--/…l/dist/regl.js:5897), <anonymous>:344:11)
    at Output.REGLCommand [as draw] (/Users/--/…l/dist/regl.js:9991)
    at Output.tick (/Users/--/…h/src/output.js:121)
    at HydraRenderer.tick (/Users/--/…/hydra-synth.js:434)
    at Engine.<anonymous> (main.js:236)
    at Engine.emit (events.js:315)
    at Engine.tick (/Users/--/…af-loop/index.js:42)

an example code that give me the error is

  msg.setPort(3333)

let freq=0

msg.on('/dirt/play', (args) => {
   freq = 300
   console.log(args)
  })
  
osc(()=>freq).out()

I try to eval code by line, by block and whole file but the result is the same.
The only workaround that i find is group all code in the function message but this create some trouble with output different from out()

msg.setPort(3333)
msg.on('/dirt/play',(args)=>{
  bd=args[0]
  console.log(args)
  osc(100)
  .scale(()=>bd*.2)
  .out()
})
let bd=10

Pulsar ver 10.110.0
OS Ventura 13.5.2
Processor M2

Every answer will be appreciate.
Thanks
glitched

I think you need to initialize the variable with window.variableName = 0 instead of let variableName = 0 so that it gets added to the global scope

so, for example, the code above should work if you write it like this instead:

msg.setPort(3333)

window.freq=0

msg.on('/dirt/play', (args) => {
   freq = 300
   console.log(args)
  })
  
osc(()=>freq).out()

That's seem work, thanks a lot.
I suppose that didn't need the window. or let. because in all example that i found no one use it.
Probably is some of my mistake in config or i don't know.

Thanks a lot Ndr0n now i can start to play :smile:

Glitched

1 Like