Newbie: Functional difference between cards and stacks?

Ken Ray kray at sonsothunder.com
Fri Mar 25 19:18:56 EST 2005


On 3/25/05 3:05 PM, "Nicole Freed" <nfreed at hotpop.com> wrote:

> My first question is simple: What is the functional difference
> between cards and stacks? I get the visual metaphor, but don't really
> get when to use stacks, substacks, or cards.

First of all, welcome to the list! Don't worry about "newbie" questions...
send 'em to the list and one of us will be happy to answer.

Now to your question: think of stacks the same as windows - they are
"containers" for content. The actual content sits on cards. In fact, you
can't have a stack without a card. So buttons/fields/etc. all sit on a card,
and the card(s) are contained within a stack (or 'window').

Stacks may or may not other stacks. A stack that contains other stacks is
called a 'mainstack', and the stacks that are contained by the mainstack are
called 'substacks'. Snd since there is no functional difference between a
stack that *contains* other stacks, and a stack that *does not contain*
other stacks, they are both called 'mainstacks'. There *is* however, a
functional difference between a mainstack and a substack, however, which is
as follows:

  1) Mainstacks have a physical representation on disk as a file with an
icon (this is called a "stack file"). Substacks, because they are "embedded"
into the same file as the mainstack, do not have their own physical
representation on disk.

  2) The message passing hierarchy is different when substacks are involved.
Normally, if you click a button on a card in a mainstack that *does not*
contain any substacks, the message will travel as follows (NOTE: This
example if simplified for the purpose of clarity, as it doesn't take into
account groups, libraries, frontscripts, backscripts, etc.):

  button -> card -> mainstack -> Revolution Interpreter (the "engine")

When the button sits on a card of a substack, the message travels in this
manner:

  button -> card -> substack -> mainstack -> engine

> From my graphics 
> background, I'm most familiar with programs like Photoshop and
> Illustrator (and like Revolution ; ) that have a main window for user
> input and smaller floating windows for palettes and toolboxes. I
> understand from some of the instructions that those palettes and
> toolboxes are best made separate stacks (external stacks or
> substacks?) but I'm not clear on why. What kind of functionality do
> stacks (and substacks) provide that cards don't? When would I use
> either?

As to when to use mainstacks or substacks, that is a personal choice.
Personally,  I usually use substacks for things like dialog boxes that my
program will display, or palettes/toolbars/toolboxes, and use mainstacks for
the primary content windows of my program, or for "modules" that may need to
be replaced later on (remember that mainstacks have a stack file on disk, so
if I was, for example, making a Search window that I thought might get
upgraded independently, I might make it a mainstack instead of a substack).

> For my first real project, I'd like to design a flash card program
> similar to CramSession (http://www.bainsware.com), but with a more
> flexible fill-in-the-blanks multiple-choice answer format. In other
> words, for each card, the user types in the "answer," then highlights
> individual words or phrases to be turned into "blanks" on the
> "question" card. Each blank could have multiple possible answers (or
> not).
> 
> In my thinking about this, it seems that there need to be separate
> windows for the list of stacks, list of cards within each stack,
> entering and editing answers, and then showing the cards (front and
> back), and possibly other windows that I haven't thought of (such as
> Preference panels). How would I go about planning this project, and
> then thinking about the interrelationships of the various cards and
> stacks?

Well, one approach might be to put all of the flash cards (I'm going to use
the term "flash card" to indicate the 'front' and 'back of a physical flash
card, and the term "card" to indicate a card in a stack in Revolution) into
one stack, where the odd cards (cards 1,3,5,7,etc.) are the "front" of the
flash card and the even cards (cards 2,4,6,8,etc.) are the "back" fo the
flash card. This way you can step through each card in sequence - question,
answer, question, answer, etc.

If you do it this way, you might have a little trouble in assembling the
list of flash cards, as it would require getting every other card to build
the index of all the flash cards in your program.

So perhaps a better way would be to have two stacks: one holds all the
"fronts" (question cards) and the other holds the "backs" (answer cards).
Name each card something descriptive that you will use to display in your
index. You can then get "the cardNames" of the stack to get a quick list of
all the flash cards in your program. When someone wants to check their
answer, you can open the same-numbered card in the answer stack. So you
could do something like:

   -- button "Check Answer" in stack "Questions"
   on mouseUp
     put the number of this card into tNum
     go card tNum of stack "Answers"
   end mouseUp

The index itself would probably be another stack - I don't know if you'd
want to make this a palette or not, that's up to you. Now you could make
these all three separate mainstacks (i.e. 3 files on disk), or you could put
them all into a single mainstack as 3 substacks (and use the mainstack's
card for things like an intro, or about box, etc.), or a combination. If it
were *me*, I'd make them all three as substacks of a single mainstack so
that distribution is easier (a single file), but that's me...

Hope this helps,


Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list