# DynamicModule in packages [closed]

I want to write a Package with a function in it. fun[]:= (DynamicModule[{},(a=10;a)]) . This works fine,but when i call it twice, they are related to each other. how do i localize the values?

-

## closed as too localized by Ajasja, Artes, Mr.Wizard♦Jan 19 '13 at 8:19

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

I recommend reading the help pages in the documentation center of Mathematica on DynamicModule. Let's consider the first example that is shown in the help and assign it to a function fun[]:

fun[]:= DynamicModule[{x}, {Slider[Dynamic[x]], Dynamic[x]}]


If you now call fun[] twice, the variable x will be local in each DynamicModule. The first Slider won't change the value of x in the second Slider. Your achieve a local variable by putting it into the curly brackets at the beginning of your DynamicModule (similarly to Module).

For your example, you have to put a into the curly brackets. Otherwise it will be globally accessible:

fun[]:= DynamicModule[
{a},
a=10;
a
]


Now a is a local variable inside the DynamicModule assigned to fun[].

-