AFAIK all parameters passed to a handler can be optional, but what is important, is the order that they are passed. If your handler requires a particular parameter then you just need to handle the case where it may be empty.
Here's a couple of button scripts to demonstrate:
Code: Select all
# Place in a Button Script - creates a small rectangle when clicked
# Holding the shift Key down when clicking the button adds a border
# Try Shift+Ctrl or Shift+Alt or Shift+Cmd to see the different parameters being passed
on mouseUp
if exists(graphic "myRectangle") then delete graphic "myRectangle" # Clean up
# Set up the parameters
put "100,100,200,200" into tRect
put "255,150,150" into tColor
if the shiftKey is down then # Adds border parameters
put 10 into tBorder
put "255,0,0" into tBorderCol
end if
switch
# Note the double comma - Parameters can be missing,
# but they still need to be passed in the correct order
case the shiftKey is down and the ctrlKey is down
addRectangle tRect, , tBorder, tBorderCol
break
case the shiftKey is down and the altKey is down
addRectangle tRect, tColor, , tBorderCol
break
case the shiftKey is down and the cmdKey is down
# Parameters missing from the end don't require extra commas
addRectangle tRect, tColor, tBorder
break
case the shiftKey is down
addRectangle tRect, tColor, tBorder, tBorderCol
break
default
addRectangle tRect, tColor
end switch
end mouseUp
private command addRectangle pRectangle, pColor, pBorderWidth, pBorderColor
create invisible graphic "myRectangle"
set the opaque of graphic "myRectangle" to true
set the rect of grc "myRectangle" to pRectangle
set the backColor of grc "myRectangle" to pColor
if pBorderColor is not empty then put 5 into tLineSize # We need a lineSize value to see the coloured border
set the lineSize of grc "myRectangle" to max(tLineSize,pBorderWidth)
set the foreColor of grc "myRectangle" to pBorderColor
set the visible graphic "myRectangle" to true
end addRectangle
Code: Select all
# Place in a Button Script, use shift, ctrl, alt or cmd keys to try the options:
on mouseUp
put 10 into tA
put 20 into tB
put 30 into tC
put 40 into tD
switch
# Note the double comma - Parameters can be missing,
# but they still need to be passed in the correct order
case the ctrlKey is down
answer addNumbers(tA, , tC, tD)
break
case the altKey is down
answer addNumbers(tA, tB, , tD)
break
case the cmdKey is down
# Parameters missing from the end of the list don't require extra commas
answer addNumbers(tA, tB, tC)
break
case the shiftKey is down
answer addNumbers(tA, tB)
break
default
answer addNumbers(tA, tB, tC, tD)
end switch
end mouseUp
function addNumbers pA, pB, pC, pD
put pA + pB + pC + pD into tAnswer
return tAnswer
end addNumbers
Paul