Expression help

Hi all,

is there a way to have an expression store a value, and add another to it (based on a frame by frame change in an axis value) - i need it to accumalate over time.

and then is it possible to compare the value from one frame to the same value on the previous frame?


Not sure what you mean by “store a value” but I think the expression you are looking for is eval. It means “evaluate.” If, for instance, you wanted to find out the difference between the x position between the current frame and the previous, the expression would be eval(axis_name.position.x,frame)-eval(axis_name.position.x,frame-1)

1 Like

Sounds exactly what i was after, thanks Tim.

The first part was meaning a way to copy over the number, eg position x, then on frame 2 add the value from x to the previous one…

So if x was 1 on frame 1, 5 on f2, 7 on f3, the resulting expression would accumulate those over the frames as 1, then 6, then 13.

That may be where you run into a problem. The expression eval does it’s namesake per frame and variables are initialized at evaluation, which would also be per frame. You essentially need a solver…

You could potentially hack it by writing out a small frame to disk fed by a color source that is the color or the variable you want to accumulate and read that value back in via a read node connected to a matchbox that writes the measured pixel value out to an interface component available to expressions which in turn increments the measured value to the to the the expression driving the color source output you write out to disk.

This kind of disk based accumulation is the basis for @lewis OFOW fluid sims. The component I’m not sure of, is the shader that can read the color values of a pixel coordinate fed from an input… sure one must exist.


You can use a combination of eval and if then expressions to achieve what you are after. Though it might not worth writing it if it’s more than a few frames with this method.

This is an older post now. But I love using expressions. Did you come up with a solution?

i started trying out variations on eval and the if/then expressions, and was heading towards the result i wanted…not there yet but its a personal project so only doing it every now and then. I have a few ideas to try out but getting the time to experiment is the main obstacle (as well as having no clue what i’m doing!)