After this lesson
- Distinguish a number, Point and text.
- Understand operator precedence and Lua conditions.
- Clamp the result to the parameter range.
Before you start
- Composition
- A separate Fusion Composition. 1920×1080, square pixels, 25 fps.
- Parameter
- Merge1 → Blend
- Range
- Start at comp.RenderStart. Reference frames are local unless stated otherwise.
Simple Expressions use Lua syntax with Fusion extensions. This is neither JavaScript nor the After Effects expression language. The built-in Expression modifier is another, separate mechanism with its own inputs and rules.
Numbers and operators
Use a decimal point: 0.25. Multiplication is *, division is /, exponentiation is ^ and remainder is %. Parentheses make the evaluation order explicit. 1/2*4 returns 2, while 1/(2*4) returns 0.125.
Comparisons are ==, ~=, <, <=, > and >=. A single = is not a comparison. Concatenate strings with .. rather than +. Names are case-sensitive.
One input, one expected type
Return a number for Size. Use Point(x,y) for Center. Return text for Styled Text, for example Text(string.format("%03d", 12)). A point object cannot simply be added to an ordinary number without conversion.
math.sin, math.cos, math.abs, math.floor, math.min and math.max make the intended functions explicit. math.sin and math.cos take radians. Do not automatically carry units over from another expression system.
Clamping a range
Combining min and max clamps a value to an interval. This is useful for opacity, progress and parameters where negative values make no sense.
math.min(1, math.max(0, (time - comp.RenderStart) / 30))Predictable precedence and conditions
Parentheses define the order explicitly; exponentiation precedes unary minus. Therefore −2^2 gives −4, while (−2)^2 gives 4. Use a decimal point, not a comma: 0.25 is a number, while commas separate function arguments. Equality uses ==, not =; inequality uses ~=.
Lua treats false and nil as false, but not zero. Therefore iif(0, 3, 9) does not mean that zero is off: it selects 3. Compare numeric switches explicitly, for example n > 0. This matters when bringing habits from JavaScript or Python.
| Notation | Result / meaning | Common mistake |
|---|---|---|
| 2^3 | 8 | This is exponentiation, not bitwise exclusive OR. |
| -3 % 2 | 1 | Lua remainder uses a quotient rounded down. |
| time == 10 | Logical condition | A single = does not test equality. |
| math.sin(math.pi/2) | 1 | The argument to math.sin is in radians. |
One input, one contract
A number suits Size or Blend, but Center expects a coordinate pair. Point(0.5, 0.5) creates a point at the center of the frame; two comma-separated numbers without Point do not replace it. Styled Text needs a text result. Wrap a counter calculation in Text, and check formatting separately from the mathematics.
Use the input names generated by Pick Whip. The displayed label and internal identifier can differ. The laboratory supports only a safe numeric subset: success there does not prove that a node exists or a string function is available in your composition.
Parameters and ranges
| Parameter | What it changes | Example / check |
|---|---|---|
| math.min(1, …) | Upper limit. | Prevents Blend from exceeding 1. |
| math.max(0, …) | Lower limit. | The result stays at zero before the transition starts. |
| 30 | The linear rise duration in frames. | The value at local frame 15 is 0.5. |
| Point(x,y) | A two-component position result. | Point(0.5,0.5) is the center. |
USE IN A COMPOSITION
Build it in Fusion
Merge1 → Blend
Solid lines are node connections in the Flow. A dashed line is a parameter dependency configured in the Inspector.
Connections by port and parameter4
Color is determined by the destination input. Dashed connections are configured in the Inspector; they do not add an RGBA wire to the Flow.
Assembly steps
- Create Background1, Text1 (Text+) and Merge1. Connect Background1 to the yellow Background input and Text1 to the green Foreground input; connect Merge1 to MediaOut1.
- Enable Expression on Blend.
- Paste the clamped linear ramp.
- Check local frames 0, 15, 30 and 60.
math.min(1, math.max(0, (time - comp.RenderStart) / 30))Expected result. Blend reads 0, 0.5, 1 and 1: the title stays visible after appearing.
Checkpoints
| When / what to check | Expected | Why check it |
|---|---|---|
| 0 | Blend=0 | The title is hidden. |
| 15 | Blend=0.5 | Halfway through the linear transition. |
| 30 and 60 | Blend=1 | The ramp holds after completion. |
INTERACTIVE EXAMPLE
Change a parameter. Compare the result.
A number in the formula becomes opacity in the frame
Merge1 → Blendunder control.MERGE → BLEND
The linear ramp is clamped to 0…1. Move the playhead beyond the final transition frame: the title remains visible.
With duration 30, frames 0, 15, 30 and 60 give Blend values 0, 0.5, 1 and 1.
Formula for the current settings +
math.min(1, math.max(0, (time - comp.RenderStart) / 30))The article's numeric formula is evaluated. The ramp controls foreground Blend; the background stays unchanged.
Errors and troubleshooting
Error near a decimal number
Replace the decimal comma with a point.
A formula from another tutorial is rejected
Check the environment: Simple Expression, Expression Modifier, Custom Tool and scripts are not interchangeable.
Independent exercise
Clamp an arbitrary number v to the range 0.2–0.8.
Show the solution and explanation
math.min(0.8, math.max(0.2, v)). In a real expression, replace v with a number, formula or existing input.
Continue learning
Official sources
An original educational walkthrough. The browser model explains the principle but does not run Fusion. Control placement depends on the version; save the original composition before replacing a parameter's control source.