sharvy@reed.UUCP (Harvey Marvy) (01/05/91)
I'm having a hard time figuring out an elegant way to get input from the user in the middle of handler without using ask and answer. I wish to avoid the dialog boxes for asthetic reasons. Suppose I want to ask a yes-or-no question. I can put the question into a field and then make 2 buttons named "yes" and "no" to get an answer, but if I put the question from inside a handler the handler will just continue to execute without waiting for the response. I tried making the next line 'wait until response is not "" ' where response was a global variable changed in the yes/no button handlers, but this didn't work. So what's the problem. I have to believe I'm just being dense, and their's an obvious solution to this problem. Any enlightenment will be appreciated (if recognized). Ben.
jdevoto@Apple.COM (Jeanne A. E. DeVoto) (01/06/91)
In article <15845@reed.UUCP> sharvy@reed.UUCP (Harvey Marvy) writes: >I'm having a hard time figuring out an elegant way to get input from the user >in the middle of handler without using ask and answer. I wish to avoid the >dialog boxes for asthetic reasons. Suppose I want to ask a yes-or-no >question. I can put the question into a field and then make 2 buttons named >"yes" and "no" to get an answer, but if I put the question from inside a >handler the handler will just continue to execute without waiting for the >response. I tried making the next line 'wait until response is not "" ' where >response was a global variable changed in the yes/no button handlers, but this >didn't work. (The reason this doesn't work is because HyperTalk can only execute one handler at a time. Since your original handler is already executing, the mouseDown/mouseUp handlers for the Yes and No buttons are suspended until the current handler is finished. Since they can't execute while your handler is tying up the interpreter, the global never gets changed.) It seems to me that you want your stack to be in a modal situation -- that is, a situation in which the user is required to answer the question before doing anything else -- and in these situations, presentation of a modal dialog is the usual way to indicate that the user must answer the dialog before doing anything else. Bypassing this well-understood indication may confuse the hell out of the user. However: - Depending on the nature of the aesthetic objection, you may still be able to use a modal dialog. If you don't like the answer dialog HyperCard provides, but a dialog box is not per se a problem, there are assorted XFCNs that will present a modal dialog of your own design and return the answer to your handler. - If you are really set on presenting the choice on a card, I'd suggest some variation on the following: on mouseUp -- do setup stuff, show buttons, etc. repeat wait until the mouseClick if the clickLoc is within the rect of button "Yes" then put "Yes" into theAnswer exit repeat else if the clickLoc is within the rect of button "No" then put "No" into theAnswer exit repeat else -- optional beep answer "You must click Yes or No." end if end repeat -- do whatever you need to with the value of theAnswer end mouseUp - If I'm wrong and you don't really want a modal situation -- if it's OK for users to do something other than answer the question -- splitting the handler would be a better answer: on presentDialog -- do setup stuff end presentDialog on mouseUp -- in Yes button -- do whatever you want to do end mouseUp If there's any information from the original handler that the Yes and No buttons need, that information can be stuffed into a global variable. -- ========= 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. |