Login  Register

Re: User-defined functions

Posted by Michael Cammer on Aug 03, 2006; 5:47pm
URL: http://imagej.273.s1.nabble.com/User-defined-functions-tp3701916p3701922.html

This works for me.  Maybe the problem was having the macro and function
both named test?

var someText = "";

macro "Test" {
   testText();
   print(someText);
}


function testText() {
someText = "Here is some text";
}













At 04:09 PM 08/03/06 +0200, you 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!?
>
>Andy
>
>On Wed, 2006-08-02 at 19:15 +0200, seb wrote:
> > Andy Weller wrote:
> > > Hi all,
> > >
> > > (I will document the response to this on the Docs website soon.)
> > >
> > > For some reason I can't set global variables outside my macro?! The
> > > macro just doesn't start.
> >
> > Hi Andy,
> >
> > If you use the macro editor and want to run it, try to install it first
> > (usually Ctl-I) and start it from the menu.
> >
> > >
> > > What if I want to return 2 variables instead of just the 1 - or is this
> > > bad practise? (I guess I can call a function from within a function.)
> > >
> > > macro "test"
> > > {
> > > x, y=doit();
> > > print(x, y);
> > > }
> > >
> > > function doit()
> > > {
> > > x=10;
> > > y=20;
> > > return x, y;
> > > }
> > >
> > > ?!?
> >
> >
> >
> > Your function can't return multiple values, but you can return an array:
> >
> > function foobar()
> > {
> > output=newArray("foo","bar");
> > return output;
> > }
> >
> > macro "test"
> > {
> >   strarray=foobar();
> >   print (strarray[0]+"\n"+strarray[1]);
> > }
> >
> > Sebastien

____________________________________________________________________________
Michael Cammer   Analytical Imaging Facility   Albert Einstein Coll. of Med.
URL:  http://www.aecom.yu.edu/aif/