Re: function cannot make global change to variable?
Posted by
Aryeh Weiss on
Jun 23, 2014; 2:01pm
URL: http://imagej.273.s1.nabble.com/function-cannot-make-global-change-to-variable-tp5008371p5008373.html
On 6/23/14, 1:34 PM, Lars Damgaard wrote:
> Hi,
> I am trying to make a macro that contains function ("printtimesince") that prints the difference between a variable "lasttime"and getTime() and then resets lasttime to getTime(). This should allow me to track the time spent between calls for debugging purposes. However, contrary to what I can read in the docs, I don't seem to be able to keep lasttime's new value after the call to the function. A samle code is below.
> Can anyone help?
> Lars
>
>
> macro "timetest" {
>
> var lasttime;
>
> lasttime=getTime();
> print("lasttime-getTime before wait: "+getTime()-lasttime);
> wait(1000);
> print("lasttime-getTime after wait before call to printtimesincelast function:: "+getTime()-lasttime);
> printtimesince(lasttime, "time label text");
> print("lasttime-getTime after call to printtimesincelast function:: "+getTime()-lasttime);
>
> }
>
> function printtimesince(lasttime, text) {
> print("getTime-lasttime in start of func: "+getTime()-lasttime);
> print(text+": "+getTime()-lasttime+" ms");
> lasttime=getTime();
> print("getTime-lasttime in end of func: "+getTime()-lasttime);
> }
>
> --
>
Take lasttime out of the argument list, and it will be global.
Since it is global you dont need it in the argument list.
The way you have it, ;the function's asttime is local to that function.
--aryeh
--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel
Ph: 972-3-5317638
FAX: 972-3-7384051
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html