Login  Register

Re: User-defined functions

Posted by Andy Weller on Aug 03, 2006; 3:09pm
URL: http://imagej.273.s1.nabble.com/User-defined-functions-tp3701916p3701921.html

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