Reusing a group on the same card

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lexogram
Posts: 13
Joined: Fri Oct 17, 2014 6:58 pm

Reusing a group on the same card

Post by lexogram » Mon Oct 20, 2014 8:10 pm

Hi LiveCoders!

I am creating an app to demonstrate how Grade 2 Braille is written. Each character pattern is composed of 6 dots. I have created a group called Braille Dot containing 6 oval graphics. I have added a script to the group so that a call to setPattern(pInteger) will set the background colour of the appropriate dots to black to create one of the 64 possible patterns. So far so good.

I now want to show a group of symbols, to create a word. For example, the word "teaching" would be written in 4 patterns as "t-ea-ch-ing", and "learner" would be 5 patterns as "l-e-ar-n-er".

I had hoped that I would be able to add my Braille Dot group to the card multiple times, and to call setPattern() on each group independently, so that each instance of the group would show a different pattern. As far as I can tell, I will have to create many distinct groups, each containing 6 distinct oval graphics. This seems like unnecessary duplication.

I understand that I can set the `behavior`of each group to point at one unique control, so I do not need to duplicate the script.

Is there a similar technique that would allow me to display many instances of the same control on the same card, each with a different set of properties (similar to setting `sharedText` property for a field to false)?

Thanks in advance,

James

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

Re: Reusing a group on the same card

Post by dunbarx » Mon Oct 20, 2014 8:33 pm

Hi.

If I understand your problem, you will want to store and hide each of the 64 unique patterns. If you name your graphics "t", "ea", "ch", and "ing", (and so on), then to assemble the word, you can clone each one in turn, setting their respective locs as required, (pseudo):

Code: Select all

get "t,ea,ch,ing"
repeat for each item tPattern in it
  clone grc tPattern
  make that last grc visible, since it derives from a hidden control
  set the loc of grc tPattern to the right spot for that graphic
end repeat
Or do I have this totally wrong?

Craig Newman

lexogram
Posts: 13
Joined: Fri Oct 17, 2014 6:58 pm

Re: Reusing a group on the same card

Post by lexogram » Mon Oct 20, 2014 9:50 pm

Hi Craig,

Thanks for your reply.

In fact, a Braille Dot group will work in two different ways:
* The user can touch each of the dots in any pattern, to toggle it on or off, to create a new pattern.
* When a word is displayed, the various pattern will be sent to a set of Braille Dot groups, to spell out the word automatically.

I plan to have a set of groups permanently on the screen, in fixed positions. Their content will vary according to the user's interactions.

Because the user can change the pattern of dots, it makes more sense to have an "editable" pattern rather than a set of predefined images.

If I understand your answer, it is this: I can use `clone` to create multiple instances of a group on a card.

Am I right? Does this have to be done using code, or is there a way to create a clone using the GUI?

James

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

Re: Reusing a group on the same card

Post by dunbarx » Mon Oct 20, 2014 11:12 pm

You can duplicate a control when in edit mode, either via selecting the control and "duplicate" (cmd-D), or by option-dragging a pre-selected control. I am not sure this is what you want to do, though.

Or you can create an environment that creates a duplicate when, say, the user option-drags in run mode. But this requires coding, and would be merely a UI feature.

Craig

lexogram
Posts: 13
Joined: Fri Oct 17, 2014 6:58 pm

Re: Reusing a group on the same card

Post by lexogram » Mon Oct 20, 2014 11:18 pm

Thanks Craig!

Post Reply