3
$\begingroup$

The variable t needs to reset to 0 if any of the other variables tab1, tab2, or x are changed. I did this by using TrackingFunction on each Control. What I would like to know is if there is a better, more efficient way of doing this without having to repeat TrackingFunction for each Control.

Manipulate[t,
 {{tab1, 1, ""}, {1, 2, 3}, TrackingFunction -> (tab1 = #; t = 0; &)},
 {{tab2, 1, ""}, {"A", "B"}, RadioButton, TrackingFunction -> (tab2 = #; t = 0; &)},
 {{x, 0}, 0, 10, 1, TrackingFunction -> (x = #; t = 0; &)},
 {{t, 0, "play"}, 0, 5, 1, Trigger}
 ]

Based on the answer to this post.

$\endgroup$
2
$\begingroup$

In your current code the resetting of t is driven by the Control object events.
The same Manipulate behavior can be achieved by using a table-driven state model instead of such an event driven model:

Manipulate[
 If[{tab1, tab2, x} === {tab1O, tab2O, xO}, t, {tab1O, tab2O, xO} = {tab1, tab2, x}; t = 0],
 {{tab1, 1, ""}, {1, 2, 3}},
 {{tab2, 1, ""}, {"A", "B"}, RadioButton},
 {{x, 0}, 0, 10, 1},
 {{t, 0, "play"}, 0, 5, 1, Trigger},
 {tab1O, None}, {tab2O, None}, {xO, None}]

Or

Manipulate[
 If[{tab1, tab2, x} === last, t, last = {tab1, tab2, x}; t = 0],
 {{tab1, 1, ""}, {1, 2, 3}},
 {{tab2, 1, ""}, {"A", "B"}, RadioButton},
 {{x, 0}, 0, 10, 1},
 {{t, 0, "play"}, 0, 5, 1, Trigger},
 {last, None}]

This is a different approach to the same problem. I leave it up to you, to judge if it is "a better, more efficient way". Instead of repeating TrackingFunction you have to introduce at least one additional variable.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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