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 |
Hi Lars,
Maybe you can return getTime() or lasttime from your printtimesince function and use that to reset the lasttime variable. lasttime=printtimesince(lasttime, "time label text"); George -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Lars Damgaard
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 |
Thanks, Aryeh, I understand it now. Lars
-----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Aryeh Weiss Sent: 23. juni 2014 16:01 To: [hidden email] Subject: Re: function cannot make global change to variable? 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 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |