Phil Davis <[EMAIL PROTECTED]> wrote:
>> On one card I have 20 buttons whose script is the same but which I now want
>> to change, preferably with some sort of repeat loop rather than manually
>> button by button, e.g.,:
>> In hindsight, I should've scripted some sort of subroutine.
>
>Good idea. To do the same kind of thing from several buttons, but with
>different values in each case, you can put a handler in each button
>script that issues a command message with a parameter or two (or
>twenty!) thrown in. Like this:
I usually do it in the following way, and I think it's very handy because you
need to edit the script only once, and you can custom the objects with
right mouse button while testing the program. It's also a lot faster than
fiddling with the settings windows.
1. Give the buttons special name/s (here "myColorButton" or
"myColorButton 1", "myColorButton number two" etc.).
2. Give the buttons some custom property (here "myColor").
3. Create a button with checkBox style, name it something like
"authorMode", and check it. As long as this button is checked
the user can change the values, so by just unchecking this button
(and by making sure the end user can not check it) you disable
the authoring parts of the scripts. A custom property of the main stack
would do as well.
4. Write something like this to the script of the stack/card:
on mouseUp whichButton
put word 1 of name of target into targetType
put the short name of target into targetName
if targetType = "button" then
if word 1 of targetName = "myColorButton" then
if whichButton = 1 then
set the backgroundColor of target to the myColor of target
else
if the hilite of button "authorMode" = true then
ask "Give myColor value for this button"
set the myColor of target to it
end if
end if
end if
end if
end mouseUp
So now when you click the buttons with mouse button 1, you activate
it's normal behavior, and as long as button "authorMode" is checked
you can change the value of the buttons by clicking them with "some
other" mouse button.
-Jarno Järvenpää