4.3 Variables

Variables are all values that change over time. Basically you can say that these are the values that drive an animation created in Xpressionist. If all values would stay static in an expression nothing would move.

In Xpressionist you can use two types of variables: system variables and custom variables.

System variables

These variables are created by Universe as the animation plays and can be used in your expressions. These variables are

time

This gives you the current time of the project back. time is always measured in seconds. When the time slider is at 2 seconds, the value of time is 2. If it is at 1:03 the value of time is 63.

frame

frame gives you the current frame number. When the time slider is at frame 20 the value of frame is 20.

The difference between the two is, that time is independent from frame. If you change the frame rate of your project, time will not change but frame will change. You can show the relation between time and frame like this:

time = frame / fps of the project

time = (current frame = 60) / (30 fps) = 2

When you change the frame rate of the project, frame will give you a different value at the same time position.

Custom variables

You can use every animation channel that you have added to Xpressionist's Active Channels list as a custom variable. When you animate that channel in Universe Animator the value changes in the expression and modifies the assigned animation channel:

Cube.Pitch_X = Ball.Pitch_X;

Now the value of the custom variable Ball.Pitch_X is assigned to the animation channel Cube.Pitch_X of the Cube.

A special type of a custom variable is a custom channel.

Defining variables

You can use the result of a statement as a variable in the following statements of an expression when you assign its value to a user defined word:

variable = sin( frame ) + Ball.Pitch_X;

This assigns the value of sin( frame ) + Ball.Pitch_X to the word "variable". You can now use "variable" in further statements. Xpressionist will insert the value of sin( frame ) + Ball.Pitch_X whenever you use the word variable in your expression:

variable = sin( frame ) + Ball.Pitch_X;

Cube.Position.X = variable;

Cube.XScale = variable;

Note: If you want to compile your expression you need to define a datatype for user defined variables. more

Indexing custom variables

Custom variables that are channels in the project window can be indexed. That means that you can not only read the current value of the channel but also any other frames value. You can index values of frames with [ frame ± X ]. If you type

Cube.Pitch_X = Ball.Pitch_X[ frame - 1 ];

Xpressionist will not assign the current value of Ball.Pitch_X to Cube.Pitch_X, but the value of the last frame of Ball.Pitch_X.

Note: If you work with indexed channels you need to offset the start frame of Xpressionist in the exectution options in the preferences of Xpressionist. Since Xpressionists start frame is 0 by default a statement as the above will cause Xpressionist to look for a frame previous of frame 0 which is not existent. This will give an error.

This can, for example, be used to calculate a value for velocity:

velocity = Ball.Pitch_X - Ball.Pitch_X[ frame - 1 ];

This defines a variable called "velocity" as the result of the calculation Ball.Pitch_X - Ball.Pitch_X[ frame - 1 ]. The statement subtracts the last frames value of the X rotation from the object Ball from the current X rotation value. When the last frames value is identical to the current frames value the velocity = 0. When the ball rotates the values will be different resulting in a number for "velocity" that increases the faster the rotation is. A shortcut for this operation is the delta function.

You can only index variables that have a corresponding animation channel in EIU. If you write an expression like this

value = Cube.Pitch_X + Ball.Pitch_X;

Torus.Pitch_X = value[ frame - 1 ];

Xpressionist will give you an error, because "value" can't be indexed, as long as it is not the name of an assigned channel in the channel list - there is no place to look for Xpressionist what the value of "value" was on the last frame.

To also be able to index a variable like "value" you have to buffer the result of the calculation Cube.Pitch_X + Ball.Pitch_X to a channel. This can be any channel of any object in the project that is available in the channel list. To keep things together it is useful to use an Xpressionist custom channel to do so: Create a channel in the preference tab of Xpressionist and name it "value_buffer" (as an example). Then add the channel to the channel list. You can now alter the above statement to this:

Xpressionist.value_buffer = Cube.Pitch_X + Ball.Pitch_X;

Torus.Pitch_X = Xpressionist.value_buffer[ frame - 1 ];

Xpressionist 3.5