Part of Code Interfering with Quantification

Hi everyone!

I have another question regarding part of my code that I cannot seem to sort out.

To preface my question, I’ll provide a paraphrased/shortened form of my code (macro language).


Dialog.addChoice(“choice1:”, newArray(“1”,“2”,“3”);
Dialog.addChoice(“choice2:”, newArray(“1”,“2”,“3”);

c = Dialog.getChoice();
d = Dialog.getChoice();

if (c == “1”) {
// settings
}

else if (c == “2”) {
// settings
}

/*

if (d == “1”) {
// settings
}

else if (d == “2”) { // if I comment out this second section, it works
// settings
}

*/

open(“image”);
if (c == “1”) 1(); else if (c == “2”) 2(); // where 1() and 2() are previously defined functions


When I run one of the functions from user input “c” on its own and comment out the parts for “d”, it runs perfectly fine, but when I do not comment out the parts for “d”, “c” begins to produce completely different results. I am open to any and all suggestions!

(P.S. I have asked so many questions on here as this is my first year using ImageJ, and everyone has been so patient and helpful in answering each and every single one of them, which I am very thankful and grateful for!)

Thanks for your time!

JChen

Looks to me like you are missing some curly brackets around the if statements following the else condition.
Try:

if (c == “1”) {
   // settings
}else{
   if (c == “2”) {
       // settings
   };
};

Hope this helps,
Volko

Hi Volko!

Hmm, it didn’t seem to fix it :(. I was trying to use an “else if” statement, and I think that is the correct way to do it in the macro language, but please correct me if I’m wrong. The weird thing is that the processes for the “c” options work perfectly fine when the sections for the settings for “d” are commented out, however, when they’re not commented out, it starts producing completely different numbers, which to me is super weird!

Hi Volko!

I finally found the issue! A couple of my variables were interfering with each other, so I just had to modify a few of them and it worked!

Thank you again for your help!

JChen