What's the difference between Custom Command, Custom Function, and Custom On?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by richmond62 » Wed Jan 01, 2020 7:46 pm

Ouch.

Has the lassie no got anything better to do with herself?

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

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by jacque » Wed Jan 01, 2020 7:47 pm

Regarding the original question: private commands and functions are intended to be used for handlers you write yourself. Public handlers are intended for built-in LC messages that are sent or responded to by the LC engine. I don't think the distinction will ever be strictly enforced. One advantage to using private handlers is that they don't need to traverse the whole message path, they are immediately executed which saves a small amount of time. I'm a bit fuzzy on how that works in practice though.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by jacque » Wed Jan 01, 2020 7:48 pm

richmond62 wrote:
Wed Jan 01, 2020 7:46 pm
Ouch.

Has the lassie no got anything better to do with herself?
I don't think that's the problem. There's some legitimate illness going on there.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by bogs » Wed Jan 01, 2020 7:49 pm

If she is still bothering with us after all these years you can probably expect retaliation to this thread.
Well, I certainly hope not, and I'm sorry I found that post at this point hee hee.
jacque wrote:
Wed Jan 01, 2020 7:47 pm
One advantage to using private handlers is that they don't need to traverse the whole message path, they are immediately executed which saves a small amount of time.
I did not know that, thanks for the enlightenment !
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by richmond62 » Wed Jan 01, 2020 7:57 pm

There's some legitimate illness going on there.
Err . . . could you please define an "illegitimate illness," please?

Presumably one that makes one feel like a "right bast*rd." :evil:

Where I come from we'd just call that "clean gyte" and be done with it.

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by bogs » Wed Jan 01, 2020 7:58 pm

How did "legitimate" turn into "illegitimate" ? Have you been hitting the 'New Year Cheer' a bit too hard today? :twisted:
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by richmond62 » Wed Jan 01, 2020 8:00 pm

jacque wrote: ↑
Wed Jan 01, 2020 8:47 pm
One advantage to using private handlers is that they don't need to traverse the whole message path, they are immediately executed which saves a small amount of time.

I did not know that, thanks for the enlightenment !
I should have thought that'd be fairly obvious as a private handler is generally stored locally
in an object or a group script rather than the stack script.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by richmond62 » Wed Jan 01, 2020 8:02 pm

How did "legitimate" turn into "illegitimate" ?
No, no booze. 8)

[ Well, not that I'm gong to admit to. ]

But the logical corollary of their being a "legitimate illness" is that there has to be "illegitimate illness."

Did nobody teach you a wee bit of basic logic sometime? 8)

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by bogs » Wed Jan 01, 2020 8:24 pm

richmond62 wrote:
Wed Jan 01, 2020 8:02 pm
Did nobody teach you a wee bit of basic logic sometime?
Apic_Logic.png
If that is what passes for logic for you, I am sticking to the booze theory!
Apic_Logic.png (65.58 KiB) Viewed 6533 times
Image

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

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by jacque » Wed Jan 01, 2020 8:36 pm

richmond62 wrote:
Wed Jan 01, 2020 7:57 pm
There's some legitimate illness going on there.
Err . . . could you please define an "illegitimate illness," please?
Munchausen syndrome by proxy, though that's not what's going on here.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by richmond62 » Wed Jan 01, 2020 8:56 pm

Anything wrong?
-
Münchhausen-AWille.jpg

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by dunbarx » Thu Jan 02, 2020 7:46 pm

Lots of noise around here.

It is true that LC does not need functions at all in order to do its work, that everything a function call does can be done in line, in a command handler.

But this would make life much more tedious, less compartmentalized, less robust, less manageable, less readable, less fun...

Consider that you want to know the number of days since the beginning of standard time, that is, the instant that the function "the seconds" began. Make a button and a two line field. Put this in the button script:

Code: Select all

on mouseUp -- everything in the handler
   put the seconds into tSeconds
   put tSeconds into fld 1
   put trunc(tSeconds/ 86400) into line 2 of fld 1
end mouseUp

-----------------------

on mouseUp -- move the actual calculation to a function handler
   put the seconds into tSeconds
   put tSeconds into fld 1
   put secondsToDays(tSeconds) into line 2 of fld 1
end mouseUp

function secondsToDays tSeconds
   return trunc(tSeconds/ 86400)
end secondsToDays
Click the button. Now comment out the first handler. Both do the same thing, eh? But if you go the function handler route, you can call it anytime you like from anywhere you like. Such a setup allows you to break out functionality (pun intended), to isolate processes, to help shorten handlers and improve readability.

To really answer your question, you will have to write a bunch of code. Just work as usual. You will soon come across a situation where you realize that having a function call really helps in one or more ways. In other words, you will know when you need to.

I can tell you that you should start to write them now, even if they can be, as in the very simple example above, be used or not, because it will then become easier when you REALLY need to.

Craig

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

Re: What's the difference between Custom Command, Custom Function, and Custom On?

Post by jacque » Thu Jan 02, 2020 8:22 pm

You can also use a return statement in a command handler. The calling handler will get the value in "the result".

But a function handler is usually easier.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply