# Manipulate inside a function definition [on hold]

I am writing a notebook where I have to configure several curves (using locators in manipulates). in order not to repeat the code, I would like to write a function that wraps a manipulate and returns the manipulated value, that does something like this:

a = MyManipFunc[];
Dynamic[a + 3]


Where the first line would display a manipulate and the second would dynamically update to reflect the value currently set.

The best I have managed to code is this: (reduced to bare minimum)

MyManipFunc[] := Module[{tt = 16},
Print[
Manipulate[
tt = t; t,
{t, 0, 10}]
];
tt
]


But it does not do what I want since it is not updated despite including Dynamic. Any pointers would be appreciated!

-

## put on hold as unclear what you're asking by Michael E2, bobthechemist, Mr.Wizard♦9 hours ago

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

Maybe I'm missing the point but tt is changing it's value while using Manipulator. Switch tt to Dynamic@tt at the end of the code to see that. –  Kuba Jul 3 '13 at 20:38
Would the much simpler expression Column@{Manipulate[a = t, {t, 0, 10}], Dynamic[a + 3]} be what you are looking for? –  m_goldberg Jul 3 '13 at 20:44
Is this what you finally want do to: MyPlotFunc[some code ... MyManipFunc[] ... some code], so you would obtain the dynamic value from inside your plot function? Intuitively, I would swap that, using MyManipFunc as a wrapper to any plot function and doing something like: MyManipFunc[MyPlotFunc, {dynamic vars}]. MyManipFunc will then pass the dynamic values as arguments to MyPlotFunc. That is also pretty straight-forward to realize. –  Theo Tiger Jul 4 '13 at 14:21
Hi, thank you all for your comments, despite it not beeing precisely what I was looking for I can make it workshops by inverting the logic as suggested by Theo. –  Vskrap Jul 6 '13 at 18:06
The OP has not visited the site for a year and the question needs further clarification --- voting to put on hold. –  Michael E2 10 hours ago

To approach the problem in the way you seem to want to, you need to pass back the symbol for tt instead of its value. Something like this will work:

MyManipFunc[] := Module[{tt = 16},
Print[
Manipulate[tt = t; t, {t, 0, 10}]
];
Hold@tt
]


and

a = MyManipFunc[];
a /. Hold[x_] :> Dynamic[x + 3]


or

Dynamic[ReleaseHold[a] + 3]


The first way can be done without a, if desired:

MyManipFunc[] /. Hold[x_] :> Dynamic[x + 3]

-