Script Improvement Advice
Cubist at aol.com
Cubist at aol.com
Thu Jun 5 12:57:02 EDT 2003
In a message dated 6/5/2003 3:22:28 AM,
use-revolution-request at lists.runrev.com writes:
>
>
>Message: 11
>
sez mpetrides at earthlink.net>
>What I tend to do is put the script in the card and then call the
>routine from the button e.g.
>
>In the button
>
>On mouseup
> DisplayElement
> --this invokes the handler named DisplayElement which is then found in
>the card script
>
>In the card script
>
>On DisplayElement
>> --this is the actual handler -- found in the card script
>> put "Hydrogen" into field "ElementNameField"
>> put "1" into field "AtomicNumberField"
[etc etc]
I think I've got a better idea. By all means let each button send a
"DisplayElement" message, which is handled by the card script -- but use custom
properties to store the actual data. Thus, button "Hydrogen" could have a property
called Name, whose value is "hydrogen"; a property called AtomicNumber, whose
value is 1; etc etc etc. Thus, the script of each button ends up looking like
this:
on mouseUp
DisplayElement (the short name of me)
end mouseUp
And in the card script, we have:
on DisplayElement DisBtn
put the Name of button DisBtn into field "ElementNameField"
put the AtomicNumber of button DisBtn into field "AtomicNumberField"
put the AtomicMass of button DisBtn into field "AtomicMassField"
put the AtomicRadius of button DisBtn into field "AtomicRadiusField"
put the IonicRadius of button DisBtn into field "IonicRadiusField"
put the OxidationStates of button DisBtn into field "OxidationStatesField"
put the State of button DisBtn into field "StateField"
put the Density of button DisBtn into field "DensityField"
# and so on, and so forth, for all the bits of data
end DisplayElements
You could take thiperty of each button, and putting a list of all the
relevant fields into a custom property of the card. Once you do that, the handler
in the card script can be condensed down to this:
on DisplayElement DisBtn
repeat with K1 = 1 to the number of items in the FieldList of this card
put item K1 of the ElementData of button DisBtn into field (item K1 of
the FieldList of this card)
end repeat
end DisplayElement
Hope this helps...
More information about the use-livecode
mailing list