Multiple instances of same function - how to manage it

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
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Multiple instances of same function - how to manage it

Post by palanolho » Sun Jun 30, 2013 5:50 pm

Greetings everyone.

little by little my app is starting to get shaped and now I'm on my next step.

so, I have a group that contains several controls/graphics inside.
first, I created all the handles to scroll the group using drag & drop.
Now, I'm going to implement the handles to drag & drop the controls within the group.

The first thing I noticed was ... "hmm I'm going to need "another" on MouseUp function...."


so, my question is:
- may I have multiple instances of the same handler in the same script? (I presume not, but just want to make sure...)
- since I have multiple different actions that will use the same handlers (like mouseUp, mouseDown, etc...) what do you think it's the best way to manage this ?

many thanks for any provided help

cheers,
- Miguel

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Multiple instances of same function - how to manage it

Post by dave_probertGA6e24 » Sun Jun 30, 2013 9:34 pm

First of all read up on "The Message Path" in Livecode. It will explain what you can do. There are lots of references to it on the forums, do a bit of a search first.

In basic terms though - you cannot have multiple copies of a handler within the 'same' script, but you can have same named handlers in the script for various parts of your objects (group, button, etc)

It would be best for you to go through some of the lessons on the RunRev site, because this aspect is one of the first covered!

Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

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

Re: Multiple instances of same function - how to manage it

Post by dunbarx » Sun Jun 30, 2013 10:07 pm

Hi.

Only the first handler in any script with a similar name will be executed. This is useful in development, where you can test multiple variants by either commenting out the others or by moving the one of interest to the top.

But your question is far more fundamental, and that is what Dave was alluding to. The work of distinguishing multiple programmatic pathways is always managed within a single handler, usually with "if-then" or "switch" control structures, very basically:

on mouseUp --your handler
if someProperty then doThis --one way
else doThat --the other way
end mouseUp

There are others.

There has never been a case, probably, in fact, no case can even be envisioned, that cannot be managed with the standard tools available in all programming languages, LC being no different. Give us an example of what you have in mind, generically, and let us see how to move this forward. The way you framed your question makes me certain that it will be easier than you currently think.

Craig Newman

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Multiple instances of same function - how to manage it

Post by palanolho » Sun Jun 30, 2013 10:37 pm

Thank you all for your replies.

Looks like there's no "special" way to do in in livecode, so I'll stick with the traditional ways :)

cheers
- Miguel

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

Re: Multiple instances of same function - how to manage it

Post by Dixie » Sun Jun 30, 2013 10:54 pm

Miguel... I think what you might be looking for is 'behaviors'... read about them in the dictionary.

Post Reply