Re: User-defined functions
Posted by
Ben.BigHair on
Aug 03, 2006; 3:36pm
URL: http://imagej.273.s1.nabble.com/User-defined-functions-tp3701916p3701925.html
Andy Weller wrote:
> Unfortunately I still can't define a global variable. Here's my code:
>
> var someText = "";
> macro "Test" {
> test();
> }
>
> function test() {
> someText = "Here is some text";
> }
>
> It just bums out and doesn't do anything at all!?
>
Hi,
I'm not sure that your macro really demonstrates whether or not the
global variable is defined - perhaps if you print the result of calling
your "test()" function? In any event you might try the saving and
installing the following. You can see that the function "test()" has
access to the global variable "specialText" even though it was only
passed the name of the calling macro.
var specialText = " which is a macro";
macro "Test1" {
myNewText = test("Test1");
print(myNewText);
}
macro "Test2" {
myNewText = test("Test2");
print(myNewText);
}
function test( caller ) {
someText = "Here is some text from " + caller + specialText;
return someText;
}
Note that you really have to install these using the
Plugins>Macro>Install after which two macros will appear under the
Plugins>Macro menus. If you try to run these from the built-in macro
editor I don't think ImageJ will know where the entry point is.
Hope this is helpful.
Ben