[comp.sys.mac.hypercard] YAHCB

taylorj@byuvax.UUCP (12/04/87)

If you use GET or PUT to put a script into a container, it works fine in
a mouseUp handler, but EXECUTES the script in a mouseDown handler!  For
example, put
     
  on mouseup
    beep 2
  end mouseup

into the card script.  Then, make a button and put

  on mouseup
    get the script of this card
  end mouseup

into its script.  When you click on the button, everything works normally,
BUT, if you change the button's script to

  on mousedown
    get the script of this card
  end mousedown

HyperCard beeps twice when you click on the button!  Also, on page 502 of
the HyperCard Hnadbook, Danny says you can type "get the script of this
stack" in the message box.  He must have a different version of HyperCard
than I do, as all I get is "can't understand arguments to command get."
 Anyone else get the same result?

Jim Taylor
Microcomputer Support for Curriculum, Brigham Young University
taylorj@byuvax.bitnet

winkler@apple.UUCP (12/07/87)

To quote a cliche: "That's a feature, not a bug."  Here's why:

The button script said:

  on mouseDown
    -- doesn't matter what goes here, but it happened to be
    get script of this card
  end mouseDown

The card script said:

  on mouseUp
    beep 2
  end mouseUp

The user observed that clicking on the button caused the card script to
execute and concluded that the "get script..." line must have executed
the card script after getting it.  In fact, what happened was that
clicking the button sent two messages to the button.  The first was
mouseDown and the second was mouseUp.  The mouseDown was caught and
handled by the button.  The mouseUp passed through the button because
there was no handler for it there and was caught and handled by the
card.  That's why changing the button script to contain a mouseUp
handler rather than a mouseDown handler suppresses the beeps -- the
button then catches the mouseUp and it does not pass on the card.

If you want the card to respond only to mouseUp's sent directly
to the card rather than also to ones that inherit down to it from a
button, you can make its first line read:

  if "button" is in the target then exit mouseUp

If you want the card the receive mouseUp's even after the button has
handled them, you can make the last line of the button script read:

  pass mouseUp

This inheritance mechanism is perhaps HyperTalk's most powerful and
carefully designed feature and it is very natural and easy to use once
you understand it.  Have a look at the help stack and Danny Goodman's
tome for more information about inheritance.  For the whole story,
including the role of XCMDs and XFCNs and the difference between
static and dynamic inheritance paths, see the diagram included with
the APDA docs.  

Dan.

taylorj@byuvax.bitnet (12/15/87)

Oops!  Boy do I feel dumb!  I understand HyperCard's message passing scheme,
but somehow spaced off and didn't realize that's why the card script seemed
to be being executed instead of "getted."  Nevertheless, what may have thrown
me off was that the script wasn't in the container after I put it there.
 Maybe I'm missing something again.  Any explanations?

Jim Taylor
Microcomputer Support for Curriculum, Brigham Young University
taylorj@byuvax.bitnet
     

edmoy@violet.berkeley.edu (02/24/88)

This one is amazing in its strangeness.  This has to do with the automatic
indentations in scripts.

Try:
	if offset("abc",it) <> 1 then

The lines following will indent as expected.  Fine.  This works, too:

	if offset(" abc",it) <> 1 then

(Note the space before the "abc".)  And this works:

	if offset("a bc",it) <> 1 then

(Note the space inside of "abc".)  But this doesn't:

	if offset("abc ",it) <> 1 then

All the lines to the end of the script are indented only to the level of this
"if" statement.

Edward Moy
Workstation Software Support Group
University of California
Berkeley, CA  94720

edmoy@violet.Berkeley.EDU
ucbvax!violet!edmoy