redefining "in#" variables in [codebox~]

José Andrés Medina Ochoa's icon

ok, idk if I'm the one missing something but this is the situation:

I'm working on a Virtual Instrument VST plugin with RNBO using the [codebox~] object. I'm using a bit complicated equations so I'm redefining the "in#" variables to new variables with other variable name, something like this:

for easy readability I'm assigning "in1" to "A", "in2" to "B", the math operation with those variables to "C", and finally sending "C" through "out1"

As a programmer, in other languages this makes sense. But, as you can see in the prev screenshot, when I finish making this changes I get these errors:

'in#' is not a valid signal reference, use 'this.in#'

I don't understand why... so then I decided to do this:

the same but without redefining the variables.

And It does compiles with no problems at all...

In this post the example code is oversimplified, but now imagine trying to use this equation:

the variables that change in the equation are: n, m, k and phi.

As you can see in this equation there are many variables and translating it to code would be hard to keep up to the variables if I use "in2" in every instance of "m", for example.

Why is this a problem in codebox~? is there a way to redefine the "in#" variables with other variable name?

José Andrés Medina Ochoa's icon

even if I follow the error suggestion to use "this.in#" instead of "in#", it still throws an error, and a more complicating one!

So what I kinda understand from this error is that it's trying to look for a "in#" variable in the current RNBO patch? how does the "this" statement work in RNBO and [codebox]?

José Andrés Medina Ochoa's icon

for now I'll have to use it without defining new variables for easy readability, but I want to know if this is intended and I'm missing something? or, is this just a bug?

LSka's icon

this works for me:

var a = in1;
var b = in2;

var c = a+b;

out1 = c;

José Andrés Medina Ochoa's icon

oh, thanks! I had to declare them... why didn't I think about that 😅

José Andrés Medina Ochoa's icon

weird... I tought that the [codebox] in [rnbo~] had the same logic as the [codebox] in [gen~]

ecuk's icon

According to the RNBO Codebox and Codebox~ Reference (beginning of the second paragraph): ‘Unline [sic] Gen, variables must be declared with var, let, or const, and functions must be declared with the function keyword.’