There are three controls in the following code: the first one is a "stand-alone" one and the other two are based on the list angle. When one of the "angles" becomes active, all of them do the same. How to prevent it?

DynamicModule[{angle = Array[0 &, 2]},
      Slider[Dynamic[x], {0, 2 Pi}], Dynamic[{x, ControlActive["a", "Inactive"]}]}, 
       With[{i = #2[[1]]}, {Slider[Dynamic[angle[[i]]], {0, 2 Pi}], 
          Dynamic[{angle[[i]], ControlActive["Active", "Inactive"]}]}] &, angle]]}]]

Mathematica graphics

  • 2
    $\begingroup$ closely related: How to track Part of Symbol [...] $\endgroup$ – Kuba Feb 28 '16 at 9:52
  • $\begingroup$ @Kuba Ugh. Dynamic is a wild beast :( $\endgroup$ – Dr. belisarius Feb 28 '16 at 10:00
  • $\begingroup$ "Dynamic is a wild beast" -- Yes, perhaps it is the proverbial dancing bear, of which was said: we should be grateful that it dances at all and not expect it to dance gracefully. $\endgroup$ – m_goldberg Feb 28 '16 at 15:20

It looks that ControlActive treats angle as a one variable which will be same for both ControlActive.

See if this help:

 DynamicModule[{angle = Array[0 &, 2]}, 
   Column[{Row@{Slider[Dynamic[x], {0, 2 Pi}], 
       Dynamic[{x, ControlActive["a", "Inactive"]}]}, 
       With[{i = #2[[1]]}, {DynamicModule[{y}, 
           Row@{Slider[Dynamic[y, (angle[[i]] = y = #) &], {0, 2 Pi}],
              Dynamic[{y, ControlActive["Active", "Inactive"]}]}]}] &,
| improve this answer | |
  • $\begingroup$ Yep! It works :) I don't find the idea of nesting neat but .... :).Thans! $\endgroup$ – Dr. belisarius Feb 28 '16 at 0:18
  • $\begingroup$ @Dr. belisarius I am trying to create different variable for each controller. The only way I have (for automatic goal) is to use DynamicModule. It is something like this angle={a,b} and then work with a and b instead of working with angle itself. $\endgroup$ – Algohi Feb 28 '16 at 0:24
  • $\begingroup$ In my real problem I don't know a priori how many "angles" I will have $\endgroup$ – Dr. belisarius Feb 28 '16 at 1:26
  • $\begingroup$ That is why is use DynamicModule to generate different variable for each element of angle $\endgroup$ – Algohi Feb 28 '16 at 1:34
  • 1
    $\begingroup$ yes,yes. Your answer works.I was referring to your previous comment "I am trying to create different variable" $\endgroup$ – Dr. belisarius Feb 28 '16 at 2:16

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.