DATJN@NEUVM1.Bitnet (Jakob Nielsen Tech Univ of Denmark) (11/11/88)
I would like to be able to associate values with buttons (e.g. a list of when it has been clicked, a pointer to a special card field which would be different for each button, a text string different from the name, etc.). As far as I can see, the only place I can put such info is in the button script, and I have hit upon the following solution which is not very clean (since I want to be able to access the instance variables from scripts higher up in the object hierarchy): The button script contains: on mouseUp instanceVarIdea -- start the script which tries out the idea end mouseUp on myText -- the instance variable "myText" global dummyParameter -- used to communicate the result of the instanceVar put "This is some text" into dummyParameter end myText --------------------------- The stack script contains: on instanceVarIdea global dummyParameter send myText to the target -- calling the instance variable put dummyParameter into msg box end instanceVarIdea Do anybody have ideas for a cleaner way to program this??
duggie@Jessica.stanford.edu (Doug Felt) (11/12/88)
In article <77053@sun.uucp> DATJN@NEUVM1.Bitnet (Jakob Nielsen Tech Univ of Denmark) writes: >I would like to be able to associate values with buttons >(e.g. a list of when it has been clicked, a pointer to a special >card field which would be different for each button, a text string different >from the name, etc.). > >As far as I can see, the only place I can put such info is in the button >script [...] > >Do anybody have ideas for a cleaner way to program this?? Alas, one of the consequences of Hypertalk not being a full object-oriented language is the inability to create your own objects with state. Anyone who has tried to hack radio button groups will understand this-- better still if they have tried to provide a 'tool' for a naive user to create radio button groups. One particular hack we have used (long ago, and I have since given up scripting for writing XCMD's so we may have newer techniques) is to store information in comment lines at the end of an object's script. For instance, the last line of a radio button's script might look like this: -- group 2 Other routines (in the background script) are used to facilitate access to these 'variables'. This, needless to say, is neither clean nor fast. Given the support routines to access and modify key/value pairs, however, it is easy to code. It might also be possible to write code like this and then 'compile' it by stripping out variables and the calls to access them and replacing them with new handlers to get and set the globals. At the last OOPSLA in San Diago a person from Apple demonstrated a system for 'object-oriented' Hypertalk which 'compiled' descriptions of methods and an inheritence hierarchy into the hypertalk handlers needed to implement it. Let me emphasize, to avoid misunderstanding, that this was neither a 'compiled hypertalk' nor a new 'object-oriented' hypertalk, but simply a way to code on a higher level than hypertalk in order to make up for its lack of expressiveness. It was a cute example of hairy scripting (it has a smalltalk-like browser to facilitate access to code, too) but was not an answer to Hypertalk's problems. I don't have the presenter's name handy, but you might contact Apple. They probably won't allow him to release it, but you might be able to find out something about how he implemented it. Doug Felt Courseware Authoring Tools Project Sweet Hall 3rd Floor Stanford University Stanford, CA 94305 duggie@jessica.stanford.edu
u2dj@vax5.CIT.CORNELL.EDU (11/12/88)
In article <77053@sun.uucp> DATJN@NEUVM1.Bitnet (Jakob Nielsen Tech Univ of Denmark) writes: >I would like to be able to associate values with buttons >(e.g. a list of when it has been clicked, a pointer to a special >card field which would be different for each button, a text string different >from the name, etc.). > You might try something like this: After making a card field named "scripts" (just to see it work) make a button with the following script: I have been clicked 3 times The last time was 12:22 PM on mouseUp get script of me add one to word 5 of first line of it put the time into word 5 of second line of it put empty into last word of second line of it -- erase extra 'XM' set script of me to it put script of me into cd fld "scripts" end mouseUp ---- end of script------ Note that the first two lines are simply comments and are ignored by hypercard's message passing, but you can use then for data. (of course, it can be more than 2 lines, and can even use commas for separating items) Also note that they don't need the "--" comment delimeter, which is only necassay within a handler. Objects higher up can access the script of the target to get at the data, read it, modify it, etc. Ron Beloin u2dj@vax5.ccs.cornell.edu or u2dj@crnlvax5.bitnet
jrwg@s1.sys.uea.ac.uk (John Glauert CMP) (11/14/88)
In article <4089@Portia.Stanford.EDU>, duggie@Jessica.stanford.edu (Doug Felt) writes: > In article <77053@sun.uucp> DATJN@NEUVM1.Bitnet (Jakob Nielsen Tech Univ of Denmark) writes: > >I would like to be able to associate values with buttons > >... > >Do anybody have ideas for a cleaner way to program this?? > > Alas, one of the consequences of Hypertalk not being a full > object-oriented language is the inability to create your own objects > with state. Anyone who has tried to hack radio button groups will > understand this-- better still if they have tried to provide a 'tool' > for a naive user to create radio button groups. > ... I am no expert Hypertext programmer so this may be naive, but the scripts below do provide radio button groups: I use a hidden field to hold the state of the group given by the id of the selected button; blank implies no selection. Since button state is global, you need to adjust it to the right value when the card is opened. Script fragments below. A simplified version provides check boxes. Now the problem: I want to print this stack, but my radio buttons are not displayed properly because (it seems) opencard is not sent to cards before they are printed (hence I get the current button state everywhere). What can I do? John. In the script of the stack: on opencard set hilite of bkgnd button "M" to false set hilite of bkgnd button "F" to false if field "Gender" <> "" then set hilite of bkgnd button id (field "Gender") to true end if end opencard on radioclick group if field group = id of the target then set hilite of the target to false put "" into field group else if field group <> "" then set hilite of bkgnd button id (field group) to false end if set hilite of the target to true put id of the target into field group end if end radioclick The script of buttons "M" and "F": on mouseUp radioclick "Gender" end mouseUp