Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!mimsy!brillig.umd.edu!spector From: spector@brillig.umd.edu (Lee Spector) Newsgroups: comp.sys.mac.hypercard Subject: Message Window: probs w/global variables Message-ID: <19503@mimsy.UUCP> Date: 10 Sep 89 03:50:30 GMT Sender: nobody@mimsy.UUCP Reply-To: spector@brillig.umd.edu.UUCP (Lee Spector) Organization: University of Maryland, Dept. of Computer Sci. Lines: 45 Since I don't like the fact that the message box contains only one line (causing old commands and results to be lost) I've been trying to hack together a "message window" that'll act like windows in other interpreted languages. (Sort of like a "listener" window in Lisp). The basics are easy: grab the last line of the window, evaluate it somehow (by calling "do", moving it to the message box, or some other trick), put the result into the next line of the window, and scroll appropriately. By making this into a "returnInField" handler for the field you can get reasonable results. HOWEVER, things get considerably worse when you try to set global variables from your window. For example, try "put 5 into j". Following this with "j " gets you a "Can't understand j" message BECAUSE j WAS NOT SET GLOBALLY. This is true whether you evaluate with "do" or by moving the relevant line to the message box and sending EnterKey. Now I don't know what rules HyperCard uses for variable scoping (is this written up anywhere? Is it even consistent?) but by playing around I've found that I CAN set the variable globally by creating, on the fly, a script for a hidden field that looks like this: on kludge global j put 5 into j end kludge Then I can send a "kludge" message to the hidden field to set the variable globally. HOWEVER, I must also do this sort of thing to REFER to j; that is, in order to beable to type "j" and get 5 I must stuff it into a script with the appropriate "global" statement. NOW THIS GETS REALLY MESSY, because the script has to have a different form depending on whether the given line is a command (like put...) or an expression (like 2 + 2). Further, if I want to allow for arbitrary references to global variables then I'll have to do something very complicated (?). In short, I'd have to rewrite the hypertalk language parser and implement a copy of its run-time symbol table as well! I conclude that there must be (BETTER BE) a better way. How can I evaluate a string JUST AS THOUGH I HAD TYPED IT TO THE MESSAGE BOX AND TYPED RETURN? It seems like you could just script this, but as far as I can tell the fact that it's scripted changes the scope of the variables in the string. If anyone has any insights, knows of a write-up of HyperTalk's scoping rules, or knows of an already-written message window package, please let me know. Thanks! -Lee (spector@brillig.umd.edu)