[comp.sys.mac.hypercard] Bugs in script execution

ba0k+@andrew.cmu.edu (Brian Patrick Arnold) (11/14/89)

FIrst question:

why does "select line clickline() of the target" sometimes visually
select the field rather than the text of the field, usu. in HC 1.2.1 and
 in response to clicking on the last line of the field?  My clickline()
is about as recent as the most recently posted version. HC 1.2.2 doesn't
seem to have this problem with selecting the field instead of text.

Second question (a more important one):

SYMPTOM:
I have several scripts' handlers called in a Stack that writes to a file
at some point.  At that point, HyperCard seems to drop characters of a
handler parameter, and only part of the text is actually written.  Why?

DISCLAIMER:
What I am about to describe appears to be a real problem, and I have a
lot of HyperTalk experience, so I really want informed advice from
fluent HyperTalkers if anyone can help figure out what's going on.

MY GUESS:
I think it has to do with HyperCard running low on memory after opening
up so many scripts and calling too many handlers, and I'll explain why,
but can anybody confirm this?  The bad news is memory isn't low enough
for HyperCard to report "out of memory" and it also isn't bad enough to
complain about any recursion or HyperTalk stack overflow/corruption
problems.  I've tried to increase HyperCard's partition size under the
MultiFinder to no avail (>1000K).  I think my only recourse is to shrink
my script sizes or reduce the number/depth of handlers being called.

WHAT'S GOING ON:
In a 7.7K "Create" bg btn script, a "Create" handler responding to
mouseUp begins to call several handlers in the same script, then calls
several handlers in its 31.3K "Module ID" bg script, and then calls
several handlers in a 16.6K "Variable" bg script by sending messages
directly to the "Variable" bg.  Several handlers in both bg scripts call
handlers in the 30.8K stack script.  The "Create" handler lastly passes
text to a "SendDemos" handler in a 14.5K "I/O" bg script through
redirection in the stack script.  The "SendDemos" handler takes text as
a parameter.  The "Create" handler generates the text contents of a
container passed to "SendDemos".  My stack script performs redirection
of "I/O" handler calls like this:

ON SendDemos data, wantOutput
  send "SendDemos data, wantOutput" to bg "I/O"
END SendDemos

so that the right card or bg script receives and executes the "I/O"
message.  All messages are designed to work independant of where they
are called from.  Note that keeping parameters in quotes preserves them
unresolved as they are passed to the bg handler (yes, this works fine!).
 From any card, and in fact from several other existing btn scripts on
various bgs, this redirection works fine even now and has worked fine
for multi-line text data for several months.  However, recently, the
"Create" handler now has the first parameter passed to "SendDemos"
getting really clobbered in a strange way by the time it gets there.

MY DEBUGGING EFFORTS:
If I dump the contents of the container from the "Create" handler into a
card field right before passing it to "SendDemos", it looks OK, but
"SendDemos" drops the first 30 or so characters writing to a file -
total text in the container is a mere 50 characters or so.  Adding code
in "SendDemos" right at the start, to dump the parameter's contents
right to a card field, reveals that the data passed by "Create" via
stack script indeed got clipped by the time "SendDemos" got it.  To be
sure, on the same card/bg as the "Create" btn, if I type "SendDemos card
field debugger,false" in the message box, where card field debugger is
the card field containing the text last dumped by the "Create" handler,
the indirection to the "I/O" bg works fine, the text passed is fine and
the file is written correctly.  And as I said, the "Create" handler
simply dumps the text to the card field for debugging right before
calling "SendDemos", so it appears that neither "Create" nor "SendDemos"
independently seems to be dropping anything.  It just happens that doing
them together with all that other business beforehand appears to cause
HyperCard to drop characters in the parameter for "SendDemos".

WHAT'S GETTING GARBLED:
The text in question for one example is (<ret> = return char):
Variable marbles<ret>
Definition marbles: Undefined<ret>

And is passed fine from "SendDemos card field debugger" in the msg box,
but when passed from the "Create" script upon reaching "SendDemos":

marbles:Undefined

Note that I do not attempt, in neither "Create" nor "SendDemos" to strip
anything.  These are simply dumps of text being passed to SendDemos. 
Also note the lack of a space after the colon.  Selective clipping!

CONCLUSIONS:
Obviously, the 31.3K "Module ID" script and 30.8K stack script are
unhealthy sizes for scripts.  And obviously all this handler calling and
message passing is bound to have constraints.  But precisely what types
of problems do these cause, and is what I describe one of these
problems?  Is my only solution to minimize script sizes, or reduce the
amount of HyperTalk I can execute in a handler?  I really don't want to
move the SendDemos handler into the "Create" bg btn script, especially
if the problem rears its ugly head elsewhere.  Any insights are much
appreciated.

- Brian

ba0k+@andrew.cmu.edu (Brian Patrick Arnold) (11/14/89)

On the second question: nevermind.

The problem was actually in a prior SendDemos message sending the
definition of the variable, called somewhere deep in a "Variable" bg
script handler which shouldn't be called in the first place.  So the
problem I described isn't accurate.  HyperCard isn't to blame, it's me
to blame for my problems.

- Brian