# Trigger autorunning when not supposed to

Recently I was trying to make something where one could vary the parameters and press play to see how the animation changed. However, when I tried running the code it would just start automatically. Even if I pressed pause nothing would happen. I managed to narrow the problem down and have made a simple example to illustrate the issue.

If I run the following code I get what I want. (i.e. press play and it starts. Press pause and it stops)

Clear[step,MyAnimation,dynamicVar]
step=0;
dynamicVar={1,2};
MyAnimation[nothing_,something_]:=Module[{},step++;something+{step,step}]
Manipulate[
dynamicVar=MyAnimation[time,{1,2}];
Dynamic@dynamicVar,
{{time,1,""},1,\[Infinity],1,ControlType->Trigger,AnimationRate->2}
]


However, if I replace dynamicVar=MyAnimation[time,{1,2}];  with dynamicVar=MyAnimation[time,dynamicVar]; what I get is something which runs automatically and which one cannot not stop. (I know they give two different results, but the issue lies in the fact that I cannot stop it)

Clear[step,MyAnimation,dynamicVar]
step=0;
dynamicVar={1,2};
MyAnimation[nothing_,something_]:=Module[{},step++;something+{step,step}]
Manipulate[
dynamicVar=MyAnimation[time,dynamicVar];
Dynamic@dynamicVar,
{{time,1,""},1,\[Infinity],1,ControlType->Trigger,AnimationRate->2}
]


Any advice on how to fix this problem?

-
You're creating an infinite recursion with dynamicVar = MyAnimation[time, dynamicVar] -- what are you really trying to do? –  Mr.Wizard Sep 14 '12 at 10:30
@Mr.Wizard Every second I want MyAnimation[time, dynamicVar] to evaluate and assign the result to dynamicVar. –  E.O. Sep 14 '12 at 10:35
I'm glad you found my answer helpful, but if you wait longer (IMHO a day is good) to Accept an answer, you might get something more helpful. –  Mr.Wizard Sep 14 '12 at 10:53
@Mr.Wizard OK, I'll keep that in mind next time:) –  E.O. Sep 14 '12 at 12:00

Every second I want MyAnimation[time, dynamicVar] to evaluate and assign the result to dynamicVar

I believe you want something like this:

Manipulate[
Dynamic @ Refresh[dynamicVar = MyAnimation[time, dynamicVar], TrackedSymbols -> {time}],
{{time, 1, ""}, 1, ∞, 1, ControlType -> Trigger, AnimationRate -> 1}
]


Key elements are Refresh and TrackedSymbols.

After a bit of reading it seems Refresh is extraneous here as one can use:

Manipulate[
Dynamic[dynamicVar = MyAnimation[time, dynamicVar], TrackedSymbols -> {time}],
{{time, 1, ""}, 1, \[Infinity], 1, ControlType -> Trigger, AnimationRate -> 1}
]


It might still be useful in your full application.

-