[SOLVED]Can you call param_x dinamically inside a for function?


#1

Hey there,
I´m trying to fill an array called "states" with a bunch of boolean params I created in an object.
These parameters are called "0, 1, 2...34", and I was hoping to do something like this:

for (int i = 0; i++; i<36){
states[i] = param_i;
}

I could swear this works on arduino (which is where I usually code), but it doesn´t seem to work on Axoloti. I get the following error:

error: 'param_i' was not declared in this scope
states[i] = param_i;

Is what I´m trying to do not possible, or am I just not formatting it right? I tried using param_(i), param_'i', param_$i...


#2

It's not possible to dynamically generate variable names. So param_i will always be param_i, and never param_0, param_1 and so on.
This won't work on Arduino as well since it uses the same programming language.

What you can do is have an array with params and access those values this way: states[i] = param[i]

It might be easier for the community to help you out if you post the patch with the object code so we can take a look at what you are trying to do.


#3

Thanks for your reply :slight_smile:
What I´m planning to do is a Multi-FX with an Axoloti and a Nanokontrol 2.
Since each patch will need different configurations on the buttons (toggle or momentary) I´m trying to code an object in which I decide which buttons are toggle and which are momentary.
I have configured the Nanokontrol to have all buttons on momentary, and the leds as External (this means they will light up when they receive their corresponding CC).
This way I intend to have each patch with a different configuration on the behavior of the buttons in the Nanokontrol.
So the idea was to have 35 different boolean parameters (actually I think it´s going to be 30, since not all buttons have leds) on the object, and for those that are activated the button will have toggle behavior and on those that are not activated will behave as momentary buttons.

My "for" function was intending to fill an array of all the states of the boolean params.


#4

Easiest way is probably to use a bin32 for this.


#5

you are right!
Thanks, I´ll try that :))))


#6

Ok so far so good :slight_smile:
I have been able to fill the array with the values on the bin32.

disp_d1 = param_toggles;

if (begin == 0){
	int cuenta = param_toggles;
	for (int i=29; i>=0; i--){
		int valor = pow(2, i);
		if (cuenta > (valor-1)){
			states[i] = 1;
			cuenta = cuenta - valor;
		}
	}
	begin =1;
}

outlet_o0 = states[0];
outlet_o1 = states[1];
outlet_o2 = states[2];
outlet_o3 = states[3];

I only want to do this once when the patch is loaded, but even though I read in the forum that you can access params in the init code, I always get an error that "param_toggles" has not been declared, so I did this crappy "begin = 1" workaround.
I´m obviously not a programmer, but I understand the cleanest way would be to do this in the init code, am I overlooking something, or is my solution not too terrible?


#7

There's indeed no way of accessing params in the init section.


#8

Great, then I guess what I´m doing is just fine.
Thanks for you help @janvantomme :smiley: