Login  Register

Re: global var in macro

Posted by Michael Schmid on Jan 14, 2009; 11:11am
URL: http://imagej.273.s1.nabble.com/Reslice-stack-at-various-angles-tp3694050p3694054.html

Hi Aryeh,

as far as I understand it, global variables work with installed  
macros only, not if you use "run macro" form a text window. Your test  
macro works well if you install it.

Use Macros>Install Macros in the text window's menu or ctrl-i (Mac:  
cmd-i)

Michael
________________________________________________________________

On 14 Jan 2009, at 11:58, Aryeh Weiss wrote:


> We are having a problem with using global variables in macros. A  
> var declaration at the beginning of the macro file seems to cause  
> everything to hang.
>
> For example, here is a small macro copied from a previous posting  
> on the subject:
>
> //================
>
> var x;
>
> macro "test" {
>    x=10;
>    f();
>    print (x);
>    exit("Terminating normally...");
> }
>
> function f(){
>      x = 20;
> }
>
> //=================
>
> If I omit var x; declaration, then it runs fine (but of course it  
> prints
> that x is 10, as expected).
>
> If I include the var x; declaration, then it hangs. I ran it with  
> the debugger and single step. It advances past the var declaration  
> and highlights the
> macro "test" { line. There it stops (ie, cntl-E will not advance  
> operation to the next line).
>
> It seems something obvious that I missed. I did not find this  
> problem in the archives.
>
> --aryeh
> --
> Aryeh Weiss
> School of Engineering
> Bar Ilan University
> Ramat Gan 52900 Israel
>
> Ph:  972-3-5317638
> FAX: 972-3-7384050
>