Page 1 of 1

Syntax of expressions

PostPosted: Wed Feb 06, 2019 12:46 am
by d3zd3z
I would like to animate the r, g, and b values of the color of a background node with an expression based on time.

I selected "modify with", and chose "expression", and got a large block under the Modifiers tab. I can put simple expressions in the "Number Out" field "sin(time*20)/2+.5", but I haven't been able to figure out what language these expressions are supposed to be in.

One part of the manual suggests I should be able to use "iff(expr, a, b)" for a conditional, another suggests "if(expr, a, b)", and my experience is that neither of these works. If anything is wrong, I just get 0 out of the expression, and a very uninteresting black.

The words "and" and "or" cause this error behavior, and I was able to get "&&" and "||" to work for and and or, but I wasn't able to get an if/else type conditional to work with this.

Is there somewhere I'm missing where these are documented.

What I'm trying to do is have a pulsing pattern during some frame ranges, and during others have it held to a constant. I'd rather do this with an expression so that the parameters can easily be changed (pulse rate, how long it is on for, etc).

Thanks,
David

Re: Syntax of expressions

PostPosted: Wed Feb 06, 2019 6:12 am
by Okke Verbart
Hi David - the syntax of the expressions is pretty much LUA based, but as you've noticed there are some weird things. Indeed, in most nodes "iif" works, whereas for others (like in the pCustom, in for instance the particles tab) "if" is required. Also, I noticed that in some places things like if(a=b,c,d) work, whereas you would expect this to error (i.e. you would expect "==").

In your case, if you put a modify with expression on say the red channel, doesn't the expression below work?

Code: Select all
if(time>10 && time<20,1,0)


For me this works, so the background turns red between frames 10 & 20.

Example composition:

Code: Select all
{
   Tools = ordered() {
      Background1 = Background {
         CtrlWZoom = false,
         Inputs = {
            Width = Input { Value = 1920, },
            Height = Input { Value = 1080, },
            ["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
            TopLeftRed = Input {
               SourceOp = "Expression1",
               Source = "NumberResult",
            },
         },
         ViewInfo = OperatorInfo { Pos = { 165, 181.5 } },
      },
      Expression1 = Expression {
         CtrlWZoom = false,
         Inputs = {
            NumberExpression = Input { Value = "if(time>10 && time<20,1,0)", },
         },
      }
   },
   ActiveTool = "Background1"
}

Re: Syntax of expressions

PostPosted: Wed Feb 06, 2019 6:14 am
by Okke Verbart
or for some pulsing between frames 10 & 80:

Code: Select all
if(time>10 && time<80,sin(time*20),0)