Error: [ or . expected in line .... when trying to print a variable

I created an empty array and populate it with some values in a for loop:

 realPxValues = newArray(len); 
	        for (j=0;j<len;j++){
	        	realPxValues[j] = j*pixelHeight;        //create an array to hold line length in real px values (essentially the x-axis)   
print(realPxValues);                           <- where error shows

When trying to print it, I get the error:

Error: [ or . expected in line ....

The previous print function is executed successfully. When I change the order of the two print functions, I always get the error to be for this realPxValues.

I want to print it for troubleshooting purposes and just generally t understand when such error might occur.

1 Like

Hi @Isq,

in ImageJ macro, arrays cannot be printed using the print statement. Therefore, you can use the Array.print() statement. There are more array specific functions. You can explore them online or using the auto-completion in Fijis script editor. Just start typing Array and check what comes up:

Let us know if Array.print(realPxValues); works!


1 Like

You can print it in a loop like this:

for (j = 0; j < len; j++) {
    realPxValues[j] = j * pixelHeight; //create an array to hold line length in real px values (essentially the x-axis)

But you can also debug the script and then in ImageJ (not FIJI) you can print the current arrays, see:


1 Like

@haesleinhuepf Thanks so much, such a rookie mistake (not that I am anywhere near advanced or anything!)
I’ll keep in mind all of the array. functions, they seem super useful.


1 Like

@Bio7 thank you loads, I didn’t know the fiji macros also have debuggers, I probably should spend time doing some reading :slight_smile:

1 Like

No, ImageJ macros can be debugged in ImageJ, not FIJI!

1 Like

To be precise: ImageJ macros can be debugged in Fiji as well (as Fiji Is Just ImageJ).

But: macros cannot be debugged in the script editor (which is Fiji’s default editor).
Instead, you’ll need to start up the legacy ImageJ1 macro editor using Plugins › New › Text Window…


@imagejan Yes, thank you for the correction. @Isq by the way you can also debug ImageJ macros in Bio7 which embeds the Eclipse ImageJ plugin, too, see: