BACKGROUND OBJECTS AND SCRIPTS

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
christerp1
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 15
Joined: Tue Jan 26, 2010 1:11 am

BACKGROUND OBJECTS AND SCRIPTS

Post by christerp1 » Wed Jan 27, 2010 2:09 pm

The objective is to make a small database of cards. Adding new member is simply copying the master card and pasting it, then inserting the data, either using kb or from a file. Now, the master card contains buttons, fields and images, which then get copied to the pasted card.

Having created 100 new cards, if there is a need to do a fix to a button's script, how do I get it to the functionally same button on all cards? How shall I create / group / what ever, to have a single script (in the background), how do I define it is a background button, as it used to be in HyperCard?

rgds

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9857
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: BACKGROUND OBJECTS AND SCRIPTS

Post by FourthWorld » Wed Jan 27, 2010 2:23 pm

In Rev, groups can either be shared across multiple cards or not. This behavior is governed by a group property called backgroundBehavior.

It's set to false by default, but when set to true any new cards created from a card with such a background will have that background automatically placed on the new card.

If you want to place a background group onto existing cards, use the place command. You can remove a background from a card with the remove command.

It's worth noting that while HC gave you only one background, in Rev you can have any number of groups on any card, and any or none of them can be shared, offering a tremendous amount of flexibility in your designs.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

christerp1
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 15
Joined: Tue Jan 26, 2010 1:11 am

Re: BACKGROUND OBJECTS AND SCRIPTS

Post by christerp1 » Wed Jan 27, 2010 2:47 pm

Thank you -

I grouped the objects, and set the backgrouongBehavior true for the group. Now, as I have this group (consisting of the necessary next, previous, home and return to card visited) on the master, which I copy and paste to get the new card, these cardwise buttons get copied to the new card. Should I use a card template or how should I approach this?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9857
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: BACKGROUND OBJECTS AND SCRIPTS

Post by FourthWorld » Wed Jan 27, 2010 3:16 pm

If you copy and place the group, it will make copies of the group. Use the place command instead.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

christerp1
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 15
Joined: Tue Jan 26, 2010 1:11 am

Re: BACKGROUND OBJECTS AND SCRIPTS

Post by christerp1 » Wed Jan 27, 2010 3:37 pm

OK. Let's go through it again.
1. I design a card, with these movement buttons, group them with backgroundBehavior true, write in scripts, add the fields what I want etc. This is my master card, and expect to populate my stack with tens of these cards.
2. When I want to add a new card, which looks just like my master, the easiest is to copy the card and paste it, with all of its images, fields and buttons.
3. If I now place the group, then I will have both the buttons copied and the group, on top of each other??
4. If I place a group, and it cannot be on the master card as it gets copied, where do I put the group?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9857
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: BACKGROUND OBJECTS AND SCRIPTS

Post by FourthWorld » Wed Jan 27, 2010 3:41 pm

If you card already has a background on it, all you need to do is go to that card and issue a "create card" command. If needed, you can set the number of the created card to anything you like to reorder it as appropriate for your app. As with HC, you can lock the screen before going to the master card to create a new one, so the user never needs to see it.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

christerp1
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 15
Joined: Tue Jan 26, 2010 1:11 am

Re: BACKGROUND OBJECTS AND SCRIPTS

Post by christerp1 » Wed Jan 27, 2010 3:45 pm

I did use create card "name", but it did not copy the fields i have on the master. What do I do wrong?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9857
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: BACKGROUND OBJECTS AND SCRIPTS

Post by FourthWorld » Wed Jan 27, 2010 4:01 pm

Are those fields within a group that has its backgroundBehavior set to true?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

christerp1
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 15
Joined: Tue Jan 26, 2010 1:11 am

Re: BACKGROUND OBJECTS AND SCRIPTS

Post by christerp1 » Wed Jan 27, 2010 4:12 pm

I am getting there. Now it looks like one should group every field and button and image, and set the backgroundBehavior true for those, to really clone the card and have the scripts for objects backgroundwise rather than for each card. In HC it used to be easier, you could just click an object to be background one. Or if someone can explain me the benefit having multiple backgrounds in a stack, as it is in Revolution, maybe this crystalizes me gradually.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9857
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: BACKGROUND OBJECTS AND SCRIPTS

Post by FourthWorld » Wed Jan 27, 2010 4:40 pm

With Rev there are options not available in HC. With HC you only had one background, and no card groups at all. While Rev's flexibility does carry a modest learning curve, it ultimately makes a lot of things much simpler.

For example, suppose you have a set of controls you want to stay fixed to the bottom of the stack when the user resizes it. With HC you had no choice but to adjust the position of each control individually, but with Rev you can group them and just move the group in one line of code. Same with hiding and showing multiple controls: rather than doing it object-by-object, you can just group them and show/hide the group.

Another example might be a layout in which you have a toolbar which you want on every card, but you also have another set of controls you want on only some cards but not others. With HC you'd need to make two backgrounds, and that means replicating the objects in the toolbar on each - a bummer if you need to revise that code or add a new button there, since you'd have to make sure you update both copies. With Rev you simply place any shared group on any card you like, or remove them whenever you don't need them.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”