1
$\begingroup$

Consider the following toy example:

DynamicModule[{t = 1, v = 2},
 {Dynamic[(t = t + 1); {}, TrackedSymbols :> {v}], 
  Slider[Dynamic@v, {0, 10, 1}], Dynamic@v, Dynamic@t}
 ]

which gives enter image description here

Why isn't the first Dynamic object updated? I added the empty list because I figured the problem might have been that the object is not updated if it's not displayed on the frontend, but that doesn't seem to be enough to make it work.

$\endgroup$
  • 1
    $\begingroup$ TrackedSymbols can restrict default tracked symbols but can't extend it. So you need to add v to Dynamic's first argument so it is in the default set in the first place. Dynamic[v; t =....]. $\endgroup$ – Kuba Nov 10 '18 at 21:36
  • $\begingroup$ @Kuba ah, I didn't know that. Any way to make a dynamic statement that only updates a variable without having to print void brackets? DynamicModule[{t = 1, v = 2}, ( Dynamic[v; t = t + 1;, TrackedSymbols :> {v}]; {Slider[Dynamic@v, {0, 10, 1}], Dynamic@v, Dynamic@t} )] doesn't work. DynamicModule[{t = 1, v = 2}, { Dynamic[v; t = t + 1; {}, TrackedSymbols :> {v}], {Slider[Dynamic@v, {0, 10, 1}], Dynamic@v, Dynamic@t} }] works but it's ugly $\endgroup$ – glS Nov 10 '18 at 21:40
  • 1
    $\begingroup$ You can use Spacer[0] instead of {}, or take a look at DynamicWrapper for a more idiomatic approach. $\endgroup$ – Kuba Nov 10 '18 at 21:41
  • $\begingroup$ Could this be considered a duplicate: mathematica.stackexchange.com/q/21625/5478? More because of the answer than the question. $\endgroup$ – Kuba Nov 10 '18 at 22:16
  • $\begingroup$ @Kuba yes that essentially answers my question, thanks $\endgroup$ – glS Nov 10 '18 at 22:34

Browse other questions tagged or ask your own question.