Global Functions?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ThatOneGuy
Posts: 77
Joined: Fri Jan 04, 2013 9:57 am

Global Functions?

Post by ThatOneGuy » Wed Feb 26, 2014 5:56 am

Is there any way to set a function as "global" so that it can be called from any handler in the same stack or subsequent substacks in similar fashion as global variables?

There are other ways of doing a similar thing, but this would be very useful since I'd rather not change it to an "on ..." or need to copy the same code to every handler of my program in order to use the function, and sending the function's name and parameters (as a message) just gives errors.

If it's not possible, then I'll just find a different way to make it work.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Global Functions?

Post by jacque » Wed Feb 26, 2014 6:24 am

You can call a function remotely using this syntax:

put value("myfunction(param)",<script reference>)

For example, to call a function named "myFunction" with two parameters, where the function is in the second card of the stack, do this:

put 1 into a
put "dog" into b
put value("myFunction(a,b)",card 2 of this stack)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Global Functions?

Post by snm » Wed Feb 26, 2014 7:15 am

Why not to put the function as main stack function and call it directly?

Marek.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Global Functions?

Post by jacque » Wed Feb 26, 2014 7:53 am

snm wrote:Why not to put the function as main stack function and call it directly?
If the function is only used in a single stack, that is what I would do too. The remote call is handy if you want to use a function from a different stack and you don't have a library in use.

put 1 into a
put "dog" into b
put value("myFunction(a,b)",card 2 of stack "otherStack")

It's as close as we get for a "global" function. If there's a library in use, then that's where I would put it instead.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply