Chained behaviors

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

Post Reply
Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Chained behaviors

Post by Mag » Wed Sep 18, 2013 3:20 pm

With the release of LC 6.1 we have now “chained” behaviors
Another exciting feature in this release is the new “chained” behaviors. Behaviors help developers to put more structure into their code and avoid repetition. Less repetition = faster coding and fewer opportunities for error! http://ftp.runrev.com/forums/viewtopic. ... 01&p=80525


Is there some resources where we can find examples or documentation? (if I google this I get old lessons on, what I think to be standard, behaviors)

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

Re: Chained behaviors

Post by dunbarx » Wed Sep 18, 2013 5:01 pm

There was a thread on the mail list a while back:

http://www.mail-archive.com/use-livecod ... 41416.html

Craig Newman

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Chained behaviors

Post by Mag » Wed Sep 18, 2013 6:08 pm

Thank you Craig, maybe something more like a tutorial or a explanation would be better ... :oops:

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Chained behaviors

Post by FourthWorld » Wed Sep 18, 2013 6:18 pm

Behaviors are a little mind-bending at first, so no matter what options you may find for documentation, nothing can beat setting aside an hour or so to make a simple stack to play with them in. Once you get the hang of it, I think you'll be very pleased with the usefulness of the implementation.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Chained behaviors

Post by Mag » Wed Sep 18, 2013 6:37 pm

FourthWorld wrote:Behaviors are a little mind-bending at first, so no matter what options you may find for documentation, nothing can beat setting aside an hour or so to make a simple stack to play with them in. Once you get the hang of it, I think you'll be very pleased with the usefulness of the implementation.
I agree, but can't find any documentation. Maybe I'm looking in the wrong place.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Chained behaviors

Post by FourthWorld » Wed Sep 18, 2013 7:06 pm

The Dictionary entry for "behavior" has just enough stuff to get you started:
http://livecode.com/developers/api/5.0. ... /behavior/

There are also three Lessons available on behaviors:

How To Assign A Behavior
http://lessons.runrev.com/s/lessons/m/4 ... a-behavior

How to Override a Behavior
http://lessons.runrev.com/s/lessons/m/4 ... a-behavior

How To Create Field Placeholder Text Using Behaviors
http://lessons.runrev.com/s/lessons/m/4 ... -behaviors

Hopefully those will provide enough background to get you started experimenting. As you have questions, feel free to post them here and we'll do what we can to keep your learning productive and enjoyable.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Chained behaviors

Post by Mag » Wed Sep 18, 2013 9:31 pm

Thank you so much, I have already seen that material, very interesting, but in LiveCode 6.1 announcement you can read:
Another exciting feature in this release is the new “chained” behaviors. Behaviors help developers to put more structure into their code and avoid repetition. Less repetition = faster coding and fewer opportunities for error! viewtopic.php?t=15801&p=80525
So that is old documentation I guess (see the date). What I'm searching for is the part in bold here:
LiveCode 6.1 includes 15 new features of which 7 were user contributed - go you! We're very impressed here at RunRev at how you guys have got stuck in and started work on the engine, even before it has been modularised and tamed.

Features include:

Chained Behavior - sophisticated OOP-like programming
• iOS Remote Control Support - eg control audio and video playback via a headset
• Activation removed in Community edition - allows easy fast installation
• Locking Group Updates - speeds up custom controls composed of many objects
• Getting the Page Ranges of a Field
• Improved properties Property - list all the built in attributes of the object you are working with
• Additional statistical functions
...

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Chained behaviors

Post by FourthWorld » Wed Sep 18, 2013 10:17 pm

The new ability to chain behaviors doesn't contradict any earlier info on behaviors, it merely builds on it, so if you're already comfortable using behaviors you'll be right at home. While being able to chain them is very powerful, it's also very simple: it just lets you assign a behavior object to a behavior object.

Here's the excerpt from the v6.1 release notes:
The behavior property of a control currently being used as a behavior will now be taken into account and result in the child behavior deferring to the parent behavior in the same way a control deers to its behavior.

For example, let's say you have the following setup:

field "Action" - behavior set to button "Derived"
button "Derived" - behavior set to button "Root"
button "Root"

Then the message path will be:

field "Action"
button "Derived"
button "Root"
<parent of field>
http://downloads.livecode.com/livecode/ ... -6_1_0.pdf

There's not much more to it than that. Just as behaviors allowed you to define scripts that can control what is in effect a class of objects, chained behaviors simply provide superclasses.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: Chained behaviors

Post by dunbarx » Wed Sep 18, 2013 11:03 pm

Hi.

Start like this. Make three buttons on a card, named "B1", "B2" and "B3". Set the behavior of "B1" to "B2". Set the behavior of "B2" to "B3". Remember that the long ID must be used to reference the behavior object. Put this into the script of "B3"

Code: Select all

on mouseUp
   answer "b3"
end mouseUp
Experiment 1:

In the script of btn "B2":

Code: Select all

on mouseUp
   answer "b2"
end mouseUp
When you click on "B1", you get an answer dialog, "B2". The script of "B2" executes.

Experiment 2:

In the script of btn "B2":

Code: Select all

on mouseUp
   answer "b2"
   pass mouseUp
end mouseUp
When you click on "B1", you get two answer dialogs, "B2" and "B3". The scripts of both execute. You are essentially creating an ad hoc message hierarchy, defined explicitly by the "chain" of behaviors you declare.

Craig

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Chained behaviors

Post by Mag » Thu Sep 19, 2013 4:16 pm

Hi FourthWorld and dunbarx, thank you for your comments, now it's all clear. At, least, I think so... Is there a way to know if the behaviour is set?

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

Re: Chained behaviors

Post by dunbarx » Thu Sep 19, 2013 4:21 pm

Hi.

The "behavior" is a property, like any other, so this can be set or gotten at any time. It can be empty (default).

Craig

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Chained behaviors

Post by Dixie » Thu Sep 19, 2013 5:34 pm

Mag...

Scott Rossi sent me this stack a while ago when we were talking about 'chained' behaviours.. After looking at this stack it all made sense..:-)
Attachments
chained.livecode.zip
(2.04 KiB) Downloaded 213 times

Post Reply