Formula Device Variables

Is there any way to declare static variables that persist between cycles in the formula device? I’m working on implementing chaotic attractors for modulation, and being able to store variables internally would make things a lot easier.

Additionally, if there is a way to do it, what scope do the variables live at? Are they global and able to be referenced by code in other instances of Formula, or are they private and completely sandboxed to the specific device?

Thanks in advance!

1 Like

Yes, each formula device’s interpreter is sandboxed, so you can’t interact with other formula device’s interpreters.

But if you want to share variables within the formula calls you can simply move them out of the function which is referenced in the expression:

Formula:

-- local x actually would work here too as long as its not declared local within the example function
x = 0 

function example(s)
  x = (x + 0.01) % 1
  return x
end

Expression:

A * example(B) + C
2 Likes