Fwd: Re: User-defined functions (correction of my last post)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Fwd: Re: User-defined functions (correction of my last post)

Michael Cammer
I take back what I said.  This with the same names works fine.  Maybe it's
the version of ImageJ.  I'm still using 1.37j at my desk.

var someText = "";

macro "test" {
   test();
   print(someText);
}

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




>Date: Thu, 03 Aug 2006 12:47:51 -0400
>To: ImageJ Interest Group <[hidden email]>
>From: Michael Cammer <[hidden email]>
>Subject: Re: User-defined functions
>
>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/