1

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.

glS
  • 7,623
  • 1
  • 21
  • 61
  • 1
    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 =....]. – Kuba Nov 10 '18 at 21:36
  • @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 – glS Nov 10 '18 at 21:40
  • 1
    You can use Spacer[0] instead of {}, or take a look at DynamicWrapper for a more idiomatic approach. – Kuba Nov 10 '18 at 21:41
  • Could this be considered a duplicate: https://mathematica.stackexchange.com/q/21625/5478? More because of the answer than the question. – Kuba Nov 10 '18 at 22:16
  • @Kuba yes that essentially answers my question, thanks – glS Nov 10 '18 at 22:34

0 Answers0