Best practice for FrontScripts and Backscripts?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 73
Joined: Fri Nov 25, 2011 6:42 pm
Location: Kansas City

Best practice for FrontScripts and Backscripts?

Post by tomBTG » Wed Feb 27, 2019 4:12 pm

Hi,

I'm new to using Front/Back scripts and have a few general questions...

I found examples of drag and drop that insert the DragMove handler into a FrontScript. For every drag event, the DragMove is inserted in a FrontScript at dragStart and then removed at dragEnd.

Why not just insert it once and let it be?

When quitting the program, is it necessary to remove all Front/Back scripts, or does quitting the app remove them from memory?

What other "best practice" advice can you offer for Front/Back scripts?

Thanks,
Tom Bodine

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9660
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Best practice for FrontScripts and Backscripts?

Post by dunbarx » Wed Feb 27, 2019 4:29 pm

Hi,

Not sure what examples you are speaking of. Might you show an example script?

But is your question is broader? When to use front and backScripts?

BackScripts are easier to understand. They act as libraries in that, unless trapped earlier in the hierarchy, messages can be trapped and processed after all other objects. Have you ever placed a stack "in use"? There again, its stack script is way up the hierarchy, and any handlers in that script can be used to process messages as a catch-all.

You will know when you need to do that.

FrontScripts have their uses, too, I guess. I have never needed one. Others may offer examples of their utility.

Craig Newman

tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 73
Joined: Fri Nov 25, 2011 6:42 pm
Location: Kansas City

Re: Best practice for FrontScripts and Backscripts?

Post by tomBTG » Wed Feb 27, 2019 4:44 pm

Hi Craig.

In the case of the drag/drop that uses the FrontScript, the scenario involves dragging between fields in two separate stacks. So I guess the dragMove script is being inserted in a FrontScript to enable that cross-stack tracking.

The example that you tried out for me yesterday from my other post was inserting dragMove into a FrontScript. But it does the insertion on every drag/drop event and removes it at the end of each, which strikes me as poor optimization. What I hope to understand with this thread is why or why not do that constant reinsertion.

Thanks,
Tom Bodine

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9660
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Best practice for FrontScripts and Backscripts?

Post by dunbarx » Wed Feb 27, 2019 5:51 pm

Hmm.

What happens to the process as a whole if you do not remove the frontScript?

Anyway, I cannot see any reason to insert and remove unless other actions at other times might send a message that is caught in the frontScript, and that might be dangerous. The problem with frontScripts is that they do not allow much vetting. Since they receive messages before any other object, it is hard to filter them out.

In a backScript (or a behavior or a stack in use) it is possible to use, say, the target or some other feature or property to limit the scope of whatever action that backScript might take. That is because the backScript is above and after all the stuff that is going on in the environment. So you can:

Code: Select all

if the target is soAndSo then dontDoAnything
This is not possible with a frontScript; there is no context, because there is not yet any interaction with the environment.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7233
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Best practice for FrontScripts and Backscripts?

Post by jacque » Thu Feb 28, 2019 6:24 pm

It probably depends on where you found the example script and what's in it. If it was from a generic example or library then it probably removes itself so as not to interfere with other handlers the stack may have.

I've done the same and there's not much downside to doing it that way. LC loads everything into memory when the stack opens, so the script is already available. The insertion just puts it into the message path and that's very fast.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”