Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!clyde.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!apple!jdevoto From: jdevoto@Apple.COM (Jeanne A. E. DeVoto) Newsgroups: comp.sys.mac.hypercard Subject: Re: scope rules for scripts Summary: the ever-useful parenthesis Keywords: hypertalk, messages, scope Message-ID: <47778@apple.Apple.COM> Date: 5 Jan 91 17:44:15 GMT References: <16488@cs.utexas.edu> Organization: Apple Computer Inc., Cupertino, CA Lines: 46 In article <16488@cs.utexas.edu> brux@cs.utexas.edu (Mark Brucks) writes: >on doit arg1, arg2 > put arg1 & arg2 after card field "field 1" of card "one" > put card field "field 1" of card "one" & "foobar" into card field "field 2" >end doit > >The first line of the script works perfectly. However, the second >line generates an error message "No such card". What gives? This looks like a parsing-precedence problem to me. HyperTalk is interpreting the second line as "put such and such a field of the card named "onefoobar" into such and such a card field" -- in other words, the concatenation is done before the object-name resolution. This can be fixed relatively easily: put (card field "field 1" of card "one") & "foobar" into card field "field 2" >I realize that the current card doesn't change when a message is >sent, so that means that references to field "field 1" in the above >script default to fields of card "two" (the card sending the message). >That is why I have referenced card "one" explicitly, even though the >script belongs to card "one". This kind of scoping seems a bit >bizarre to me, and I can't find any explanation in the HC Script >Lang. Guide. This notion of the current card not changing when >a message is sent seems to suspend the usual scoping rules. Is >this right? If so, is there some mysterious advantage to this >that I haven't discovered? Basically, if a card is not specified, the current card is assumed. The current card is the one you last went to, not the one where the current handler is located. The function "the target" returns the object to which the message whose handler is currently executing was originally sent; the special object descriptor "me" is the object whose handler is currently executing. For instance, if the user clicks a button which has no script, but the mouseDown message is caught by a handler in the background script, "the target" would return the name of the button while "me" would be the name of the background. In the case of your handler above, "the name of me" would return the same thing as "the target". -- ========= jeanne a. e. devoto ======================================== jdevoto@apple.com | You may not distribute this article under a jdevoto@well.sf.ca.us | compilation copyright without my permission. ______________________________________________________________________ Apple Computer and I are not authorized | CI$: 72411,165 to speak for each other. |