Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
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
1  
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
add comment

1 Answer 1

up vote 2 down vote accepted

Based on your comment:

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.