Sending Empty Params, along with a comma delimited value (RGB in this case)

Ali Lloyd ali.lloyd at livecode.com
Tue Oct 18 05:09:39 EDT 2016


Send params are evaluated in the current context, so you can put variable
names in the list and it will work, eg:

local tRGB
put "25,25,25" into tRGB
send "doSomethingWithColor tRGB" to stack "Color Manager"

On Tue, Oct 18, 2016 at 8:55 AM Sannyasin Brahmanathaswami <brahma at hindu.org>
wrote:

> 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 props.
> 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
>
> this
>
> 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 advance
>
> 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
>  setfillRamp(pStart,pEnd,pColor1,pColor2,pAlpha1,pAlpha2)
> end setRamp
>
> # defaults are declared as constants at the top of the behavior:
>
> function setFillRamp pStartPosition,pEndPosition,pColor1,
> pColor2,pAlpha1,pAlpha2
>           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
> tGradientRamp
>           put cr &(pEndPosition & comma & pColor2 & comma & pAlpha2) after
> tGradientRamp
>           return tGradientRamp
> end setFillRamp
>
> Possibly we need yet another interim function to set up the empty defaults
> first.
>
> 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.
>
>
>
> BR
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



More information about the use-livecode mailing list