Login  Register

function cannot make global change to variable?

Posted by Lars Damgaard on Jun 23, 2014; 10:34am
URL: http://imagej.273.s1.nabble.com/function-cannot-make-global-change-to-variable-tp5008371.html

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);
}

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html