Hello Kyl.
Macros do not introduce local variable per se: it depends of what is expanded. And Curve do not introduce new variables. So, if you write a macro:
@macro_def MyCurve($start, $end, $dur)
{
Curve @grain (($end - $start)/100)
@action = {
; ... some action involving $x
}
{ $x { {$start} ($dur) { $end } } }
}
the $x
variable will refer to the $x
which is in the scope of the macro call. For instance
@MyCurve(0, 1, 10)
Group {
@local $x
@MyCurve(10, 20, 2)
}
In the first invocation, $x
will refer to a global variable (global variable are implicitly defined), and in the second invocation, the curve refers the local variable $x
introduced by the group.
If two curves overlap in time and use the same sampling variable, this variable will be updated by both curve, which usually results in unexpected results (for instance, the action of one curve may be evaluated with the value given by the other curve, if the two curve are sampled at the same instant).
If you want to uses a variable only for sampling a curve, put the curve in a group that introduces this local variable:
@macro_def MyCurve($start, $end, $dur)
{
Group
{
@local $x
Curve @grain (($end - $start)/100)
@action = {
; ... some action involving $x
}
{ $x { {$start} ($dur) { $end } } }
}
}
In this way you are assured that each macro-expansion refers to a local $x
. You can use a @UID
and @LID
to generate new names and achieve the same effect, but it is more cumbersome.
You can also uses processes instead of macros.