I do not think the problem is with Setting
. However, one can avoid using Setting
, unless for some reason the variable it depends on is unaccessible (a local variable created by a function call, inside a Module
say).
Simplest fix to the OP's code
Put Dynamic@
in front of Setting
:
Manipulate[
xp = Dynamic[First[pt]];
z = Dynamic@Setting[2*xp];
Column[{Style[StringForm["x=`1`, z=`2`", xp, NumberForm[z, 3]], Blue, 16],
LocatorPane[Dynamic[pt],
ListPlot[{{0, 0}}, Epilog -> {Red, PointSize[Large], Point[Dynamic[pt]]}]]}, Center],
{{pt, {0, 0}}, None}]
The way I might do it
f[{x_, y_}] := 2 x;
Manipulate[
Column[{
Dynamic@Style[StringForm["x=`1`, z=`2`", NumberForm[First[pt], 3], NumberForm[f[pt], 3]],
Blue, 16],
LocatorPane[Dynamic[pt],
ListPlot[{{0, 0}},
Epilog -> {Red, PointSize[Large], Point[Dynamic[pt]]}]]}, Center],
{{pt, {0, 0}}, None},
SaveDefinitions -> True]
I used a generic f
as a placed holder for an arbitrary function; SaveDefinitions -> True
makes the definition of f
be saved in the DynamicModule
created by Manipulate
. I also used NumberForm
to control how many decimals show up. I might use the Appearance
option the way @m_goldberg does, too. Whatever you might think of these alterations, I would avoid using Setting
.
Some explanation
The original code has some constructs that make it a little complicated to understand with respect to dynamic updating. Nominally the body contains the symbols xp
, z
, and of course pt
, all of which will be tracked. However Dynamic[expr]
effectively shields variables in expr
, which I can perhaps explain most easily by an example from the code. The expression xp = Dynamic[pt]
does not depend on pt
. If pt
changes value, the expression inside Dynamic
will be updated, but expressions outside of Dynamic
will not be updated (unless for other reasons an update is called for). In this case the expression inside Dynamic
is simply pt
, and I wouldn't be surprised if it is not updated at all, since such expressions are common and have no effect.
Now if we consider the code carefully, we see that all the symbols pt
appear inside Dynamic
, except the expression for z
. For z
, we have Setting[2 * xp]
, which translates into 2 * First[pt]
, without Dynamic
. Therefore the body of Manipulate
depends on pt
and will be updated when the Locator
for pt
is moved. This causes a new column with a new LocatorPane
and Locator
to be created, and it replaces the old one. Thus the dragging of the Locator
by the mouse is interrupted and stopped.
Now if we remove Setting
, we see that all the symbols pt
appear inside Dynamic
. The variable z
now equals 2 * Dynamic[First[pt]]
. Therefore the body of Manipulate
does not depend on pt
, and the body will never be updated. In particular, the line z = 2 * xp
is executed only once, when Manipulate
first starts up.
In the "simplest fix" above, the variable becomes basically equivalent to Dynamic[2 * First[pt]]
. While z
is never updated, the inside of the Dynamic
, that is, 2 * First[pt]
, is updated whenever the Locator
moves.
Thus there does not seem to be any special problem with using Manipulate
here. The main difference between Manipulate
and DynamicModule
is that Manipulate
, while it creates a DynamicModule
, does a number of things automatically for you, which can be either convenient or frustrating. DynamicModule
allows greater control over things, you have to set everything up yourself, but you get to set it up the way you like.
Setting
here may not be proper. According to documentation,Setting
is used to extract the first argument of a control object. $\endgroup$