cascade dispatch commands?

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
mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

cascade dispatch commands?

Post by mwieder » Tue Mar 12, 2019 10:52 pm

Just throwing this out here for brainstorming...

I have a need to cascade dispatch commands. What I've got is of the form

Code: Select all

dispatch "someCommand" to me with someParameters
if it is not "handled" then
  do_default_stuff
  -- otherwise the someCommand has done its work
end if
so if there is no "someCommand" in the message path code will be executed. On the other hand, if there is a "someCommand" handler in the message path (probably because of an added front- or backscript) then that code will be executed in place of the original callers default code. This works as designed. I'm happy.

The problem comes about if I want to extend that further, i.e., in a backscript I might have

Code: Select all

on someCommand @pParameters
  do_some_work_here_with_pParameters
end someCommand
and I want to give the ability to add more things later:

Code: Select all

on someCommand @pParameters
  do_some_work_here_with_pParameters
  dispatch "someCommand" to me with pParameters
end someCommand
That doesn't work because it just recurses into itself again. And

Code: Select all

on someCommand @pParameters
  do_some_work_here_with_pParameters
  pass "someCommand" to me with pParameters
end someCommand
also doesn't work for a similar reason, but only once around.

So anyone got ideas on how to cascade dispatch commands, whether or not they're found in the message path? I've got a solution that works in one specific use case, but it's too ugly to put in the margins here.

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

Re: cascade dispatch commands?

Post by dunbarx » Tue Mar 12, 2019 11:09 pm

I've got a solution that works in one specific use case, but it's too ugly to put in the margins here.
Before we get into dispatching, do you know who Pierre de Fermat was? I think you do.

Craig Newman

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: cascade dispatch commands?

Post by FourthWorld » Wed Mar 13, 2019 12:43 am

mwieder wrote:
Tue Mar 12, 2019 10:52 pm
I've got a solution that works in one specific use case, but it's too ugly to put in the margins here.
He may have an ugly workaround, but the use case is pretty awesome. He demoed it at our local LiveCode meetup last week, and when he's ready to show it I know a number of people who will be all over it.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: cascade dispatch commands?

Post by mwieder » Sat Apr 06, 2019 1:01 am

OK - it turns out that dispatch commands *do* cascade properly... the problem is in the script editor itself.

I didn't read the documentation carefully enough to realize the the "it" value returned from a dispatch command can have one of three (!) values:

handled
unhandled
passed

so the script editor (or any other code) that simply checks to see if a dispatch command has been handled

Code: Select all

dispatch "someCommand"
if it is not "handled" then
-- do something here if there was no "someCommand" in the message path
end if
will only catch one of the three values and fail if it is passed. It really should read:

Code: Select all

dispatch "someCommand"
if it is "unhandled" then
-- do something here if there was no "someCommand" in the message path
end if
Now filed as bug report #21899
https://quality.livecode.com/show_bug.cgi?id=21899

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

Re: cascade dispatch commands?

Post by bogs » Sat Apr 06, 2019 10:56 am

Looking at this kind of thing, I can see just how far I still have to go. I'd never have caught it.
Image

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”