Macro - problem with string reading

Hello,
I’m developing a macro for stacking images acquired in a HCS system. So far, the macro asks the user for the number of channels and the fluorophore order in the stack to be generated.

 macro "Image manipulator" {
 Dialog.create("IN Cell - image manipulator");
  itens=newArray("2","3","4");
  Dialog.addRadioButtonGroup("Number of channels", itens, 1, 3, 2);
  Dialog.show();
  nchannels=Dialog.getRadioButton();
  Dialog.create("IN Cell - image manipulator");
  itens=newArray("FITC", "Texas Red", "Cy3", "Cy5", "dsRed", "CFP", "YFP", "DAPI", "Brightfield");
  for (i = 0; i < nchannels; i++) {
  Dialog.addRadioButtonGroup("Channel "+i+1+" of stack", itens, 1, 9, 1);
  }
  Dialog.show();
  for (i = 0; i < nchannels; i++) {
  "channel"+i+1=Dialog.getRadioButton();
  }
}

With this script I get the following error:

Error: Statement cannot begin with ‘=’ in line 14:
"channel" + i + 1 <=> Dialog . getRadioButton ( ) ;

Any guesses ?
Thanks for the attention.

You try to assign a string to a string in line 15.

Here a revised example storing the selected channel strings in an array:

macro "Image manipulator" {
     Dialog.create("IN Cell - image manipulator");
     itens = newArray("2", "3", "4");
     Dialog.addRadioButtonGroup("Number of channels", itens, 1, 3, 2);
     Dialog.show();
     nchannels = parseInt(Dialog.getRadioButton());
     Dialog.create("IN Cell - image manipulator");
     itens = newArray("FITC", "Texas Red", "Cy3", "Cy5", "dsRed", "CFP", "YFP", "DAPI", "Brightfield");
     for (i = 0; i < nchannels; i++) {
         Dialog.addRadioButtonGroup("Channel " + i + 1 + " of stack", itens, 1, 9, 1);
     }
     Dialog.show();
     arr = newArray(nchannels);
     for (i = 0; i < nchannels; i++) {
         arr[i] = Dialog.getRadioButton();
         print(arr[i]);
     }
 }

However it is a bit unfortunate that string numbers are allowed in loops (in your example nchannels in line 6 is a string) which can lead to subsequent errors, e.g., in array size (that’s why I parse it to an integer).

2 Likes

Thank you very much, @Bio7 !
I did try to perform an array at the end of the macro, as you did, but it didn’t work. I likely wrote something wrong at the time.
Also, thanks for reminder about the parseInt. I completely forgot about it.