best practice regarding behavior references?

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
melristau
Posts: 56
Joined: Tue Jul 14, 2015 5:15 pm
Contact:

best practice regarding behavior references?

Post by melristau » Sun Aug 21, 2016 10:20 pm

Bet there's advice here but not finding...
Have behaviors linked to controls that need updating when I archive and change the name of my project. What's a smarter way of managing behavior descriptions?
rebuilding visual programming app originally created in 1993 as Hypercard stack

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

Re: best practice regarding behavior references?

Post by dunbarx » Mon Aug 22, 2016 4:05 am

Hi.

It is true that if you set a behavior, and then change the name of the enclosing stack, the behavior still reflects the old stack name. The behavior will break.

I do not know if there is a direct way to link that reference in a dynamic way, You can always manage this by hand, of course.

So is there such an expedient, as melristau requests?

Craig Newman

melristau
Posts: 56
Joined: Tue Jul 14, 2015 5:15 pm
Contact:

Re: best practice regarding behavior references?

Post by melristau » Mon Aug 22, 2016 5:37 pm

Just seems like there would be a better way than:

Code: Select all

on openStack
   setMatrixBtnsBehavior
   setTileBtnBehavior
end openStack

on setMatrixBtnsBehavior
   repeat with x = 1 to 117
      set the behavior of btn ("x"&x) to the long ID of btn "matrixBtnBehavior"
      end repeat
end setMatrixBtnBehavior

on setTileBtnBehavior
   repeat with x = 1 to 117
      if there is a grp ("x"&x) then set the behavior of group ("x"&x) to the long ID of btn "seedScript"
   end repeat
end setTileBtnBehavior
rebuilding visual programming app originally created in 1993 as Hypercard stack

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

Re: best practice regarding behavior references?

Post by FourthWorld » Mon Aug 22, 2016 6:00 pm

Many things can depend on stack names. In practice there's rarely much of a need to change them. How often do you need to change your stack names that contain behavior scripts, and what prompts the change? Perhaps we can find a much simpler solution for you.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: best practice regarding behavior references?

Post by jacque » Mon Aug 22, 2016 6:29 pm

This came up on the mailing list, and for now the only dynamic method is to use the repeat loop you posted. The team did acknowledge that less dependency would be good.

But as Richard points out, it's rare to need to change the stack name. Usually changing the label is enough.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

melristau
Posts: 56
Joined: Tue Jul 14, 2015 5:15 pm
Contact:

Re: best practice regarding behavior references?

Post by melristau » Mon Aug 22, 2016 8:55 pm

changing the label is enough.
Yes! This is a good and simple solution.

...when I got into LC a couple months ago, had fairly frequent crashes with 8. Seldom have crashes with 7.1.4 but couple times a day I duplicate and advance the version number. (Going forward, by label only.)

Thanks for help.
rebuilding visual programming app originally created in 1993 as Hypercard stack

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

Re: best practice regarding behavior references?

Post by dunbarx » Mon Aug 22, 2016 9:33 pm

Labels are not just another option to the more important and far-reaching name property. The very secondary nature of labels allows one to "see" displayed text associated with objects, but leave the referencing tasks and responsibility to the "name".

In Hypercard, I changed names often, perhaps to indicate a new functionality of a button (like toggling "show" and "hide"). This can be managed, of course, but it is far more robust and comforting to be able to separate visible attributes from referencing attributes, the latter, once set, generally permanent.

Craig

Post Reply