Given this command + function (see below) where

a)  you want to trigger it with "send" or "dispatch"
b) you only want to pass 1, or perhaps 2 or 3 values to the params, and these 
are RGB values which are *also* comma separated (therein lies the problem)

How can you pass

someEmptyParams ,,,,

along with an RGB value?

use case:

I would like to tweak gradients, run time… but not necessarily all gradient 
The algorithm here (perhaps there is a completely different/better approach) is 
to set some defaults and if e.g I just pass "red" then we get a radial gradient 
with a white center and a red exterior.

So I would like to be able to just do something like

send "setRamp ("255,0,0")  to grc "gradientBkgnd"   # which has a behavior

and let the gradient take all the other values as defaults. Of course I presume 
we can't expect the command to magically know that the singular param you are 
sending should fill the spot for the 4th parameter.

So, I tried this

send "setRamp ,,,,red,,"  # which of course fails because ramp second color 
must be an RGB value


send "setRamp ,,," & "255,0,0" & ",,," to grc colorMeditationBkgnd # also fails
# Because the RGB values are comma separated also and return params like this:

setRamp "","","","255","0","0","","",""

HQ sent me a solution but requires explicitly declaring all the empty params in 

put "" into pStart
put "" into pEnd
put "" in pColor1 # defaults to white-center
put "255,0,0" into pColor2
put  "" into pAlpha1
put "" into pAlpha2

send " setRamp pStart,pEnd,pColor1,pColor2,pAlpha1,pAlpha2"  to grc 
"gradientBkgnd" # which has the behavior below

But I would like to find a way to not have to declare those empty params when 
most if the time I just want to send 1 value over to pColor2

Any ideas? I guess this conundrum has two possible parts

1) constructing   a string for the send command with multiple params where some 
of the values are also comma delimited.
2) some magic to a pass a single declared value over to the command function as 
if it were the #4 parameter  in a way that will leave all the others empty.

command setRamp pStart,pEnd,pColor1,pColor2,pAlpha1,pAlpha2
                   set the fillgradient["ramp"] of me to     
end setRamp

# defaults are declared as constants at the top of the behavior:

function setFillRamp pStartPosition,pEndPosition,pColor1, 
          if pStartPosition is empty then put kDefaultStart into pStartPosition
          if pEndPosition is empty then put kDefaultEnd into pEndPosition
          if pColor1 is empty then put kPureWhite into pColor1
          if pColor2 is empty then put kPureBlack into pColor2
          if pAlpha1 is empty then put kDefaultOpacity into pAlpha1
          if pAlpha2 is empty then put kDefaultOpacity into pAlpha2
          put(pStartPosition & comma & pColor1 & comma & pAlpha1) into 
          put cr &(pEndPosition & comma & pColor2 & comma & pAlpha2) after 
          return tGradientRamp
end setFillRamp

Possibly we need yet another interim function to set up the empty defaults 

if the number of params is 1 then

put "" into pStart
put "" into pEnd
put "" in pColor1 # defaults to white-center
put (word 2 of the params) into pColor2
put  "" into pAlpha1
put "" into pAlpha2

end if

but it gets tricky if you start sending say, 2-3 params… probably easiest to 
find a way to construct the string where internal params include comma 
delimited RGB values.


use-livecode mailing list
Please visit this url to subscribe, unsubscribe and manage your subscription 

Reply via email to