How to package group control's behavior?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
How to package group control's behavior?
Hi all,
I'm looking for advice on good design practice. I have made a control, a time-picker, that consists of several fields in a group. The fields and the group itself have scripts that implement the control's behavior. I need to put several instances of the control on each of several cards. That's where I get stuck.
It looks like a group can be a single "thing" to LC and can be placed on multiple cards. But it seems only one instance can exist on each card, and they all must be in the same position. That's useful, but definitely not what I need. (LC8 DP1, with Shared Group automatically set.)
Instead, I'd like several instances of the control to exist separately on one card, each with its own state. I can do this by duplicating the control (group), but then all the scripts are duplicated too. That means when a bug is fixed or the behavior is changed by altering a script, the scripts of every instance of the control must be edited.
Is there any way to accomplish all this: a synthetic control, many instances of it with their own states, and the implementing scripts all in one place?
Thanks much for guidance from experienced LC developers.
Doug
I'm looking for advice on good design practice. I have made a control, a time-picker, that consists of several fields in a group. The fields and the group itself have scripts that implement the control's behavior. I need to put several instances of the control on each of several cards. That's where I get stuck.
It looks like a group can be a single "thing" to LC and can be placed on multiple cards. But it seems only one instance can exist on each card, and they all must be in the same position. That's useful, but definitely not what I need. (LC8 DP1, with Shared Group automatically set.)
Instead, I'd like several instances of the control to exist separately on one card, each with its own state. I can do this by duplicating the control (group), but then all the scripts are duplicated too. That means when a bug is fixed or the behavior is changed by altering a script, the scripts of every instance of the control must be edited.
Is there any way to accomplish all this: a synthetic control, many instances of it with their own states, and the implementing scripts all in one place?
Thanks much for guidance from experienced LC developers.
Doug
Re: How to package group control's behavior?
Hi.
I thinkI know what you mean. But you need to move all handlers to a place above all the controls on all cards. You would use control references to distinguish which group on which card was the target of the initial process. This may take careful management, since you have grouped controls in your "controls".
Have you ever used "behaviors"? Alternatively, have all handlers in either the stack script or something higher. In either case you would have to create the appropriate handler and control reference structure from the beginning.
This is little different than having a bunch of buttons and having, say, a single "mouseUp" handler in the card script. Try this. Make three buttons and name them "B1", "B2" and "B3". In the card script:
Does this help?
Craig Newman
I thinkI know what you mean. But you need to move all handlers to a place above all the controls on all cards. You would use control references to distinguish which group on which card was the target of the initial process. This may take careful management, since you have grouped controls in your "controls".
Have you ever used "behaviors"? Alternatively, have all handlers in either the stack script or something higher. In either case you would have to create the appropriate handler and control reference structure from the beginning.
This is little different than having a bunch of buttons and having, say, a single "mouseUp" handler in the card script. Try this. Make three buttons and name them "B1", "B2" and "B3". In the card script:
Code: Select all
on mouseUp
answer the target
end mouseUp
Craig Newman
Re: How to package group control's behavior?
This is exactly what behaviors were made for. The components of the the group should have no substantial scripts of their own, they should just call handlers that exist in a larger master script. That script becomes the behavior script that you assign to each group.
After that all you need to do is edit the behavior script and all copies of the group will immediately use those changes.
The behavior script should be stored separately from the groups that use it. A hidden button somewhere in the stack works fine.
After that all you need to do is edit the behavior script and all copies of the group will immediately use those changes.
The behavior script should be stored separately from the groups that use it. A hidden button somewhere in the stack works fine.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: How to package group control's behavior?
Thanks so much for your replies. Those are the kind of hints I need to shift skills from C++ and Java to LC.
In this case I was able to re-design the group control as a single field (at the cost of more complexity in the script). The behavior then puts the scripts for all of them in one place, as you suggest.
An article called "Extending the LiveCode Message Path" was also a very good read.
Onward...
In this case I was able to re-design the group control as a single field (at the cost of more complexity in the script). The behavior then puts the scripts for all of them in one place, as you suggest.
An article called "Extending the LiveCode Message Path" was also a very good read.
Onward...
-
- Livecode Opensource Backer
- Posts: 366
- Joined: Tue Apr 10, 2012 9:18 am
Re: How to package group control's behavior?
question: how do we initialize the behaviour of a button or group? is it something we tell the thing like:
or is it something you would initialize on open stack like:
Code: Select all
behaviour of me is the long id of button "behaviour"
Code: Select all
on openStack
set the behavior of button x of group "nav" to the long id of button "behaviour"
...
Re: How to package group control's behavior?
Hi ghettocottage,
So set it once (maybe with the message box) save it and that's it
Best
Klaus
If AT ALL, then: SET the behavior...ghettocottage wrote:Code: Select all
behaviour of me is the long id of button "behaviour"

But there is no need for this, behaviors are saved with the stack!ghettocottage wrote:Code: Select all
on openStack set the behavior of button x of group "nav" to the long id of button "behaviour" ...
So set it once (maybe with the message box) save it and that's it

Best
Klaus
-
- Livecode Opensource Backer
- Posts: 366
- Joined: Tue Apr 10, 2012 9:18 am
Re: How to package group control's behavior?
the answer was too simple so I was unable to see itSo set it once (maybe with the message box) save it and that's it![]()
Re: How to package group control's behavior?
I'm curious what the extra complexity was. If it involved referring to objects in the group, the "me" keyword is very convenient in behaviors because it always references the particular instance of the object that is running the script. So in the case of the groups, "field x of me" would be the field x of the particulr group instance.Pomo wrote:In this case I was able to re-design the group control as a single field (at the cost of more complexity in the script).
Since you've reduced the group to a single field object instead, it gets even simpler. Assign the behavior to the field (it no longer needs to be a group) and every reference to "me" in the behavior script will point to that specific field. I.e., "put line 2 of me" will return line 2 of whatever field happens to be executing the script. This is about as close to classes as LC gets.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: How to package group control's behavior?
Nothing to do with LC directly. I originally had a hidden field that held the picked time already parsed out, along with a field to display the time in a nice format for humans. The simplification is to parse the displayed time and generate it as needed, using only the display field.
BTW, I noticed that the control's inspector window implies you can manually type in the behavior reference. You can copy/paste, select, edit, etc. But the behavior is cleared once the inspector is closed. You actually have to set it once with "Set the behavior of...". Then it sticks forever. Bug or feature?
BTW, I noticed that the control's inspector window implies you can manually type in the behavior reference. You can copy/paste, select, edit, etc. But the behavior is cleared once the inspector is closed. You actually have to set it once with "Set the behavior of...". Then it sticks forever. Bug or feature?
Re: How to package group control's behavior?
Bug probably, if you're sure you put in the right reference. There's a weird thing with that field; if you type in a short reference it isn't accepted. If you put in a long full-stack-path reference it's accepted as correct, and then the inspector shortens it to the shorter path you tried in the first place. Or at least it used to. I've become so used to just setting it in the message box I haven't looked in a while.Bug or feature?
Have you explored custom properties as a way to store private data? Sounds like a good match for your now-missing hidden field.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com