I really have a big problem in my hands.
I spend a week rewriting the Manipulate demo to use indexed objects (use them as a structure emulation)
However, when I started, I did not know how to define them as a None control type (so that the state was maintained between each Manipulate update), so I moved them to the "Initialization" section now so that I can test the idea.
Everything works well, except for one problem:
In the Initialization section, they become GLOBAL. This means that when creating a demo and creating a snapshot of the Manipulate to be taken, then 2 Manipulations will now interact with each other in an undesirable way. They share these global variables (indexed objects). This means that if I change something in one Manipulate, another manipulator is affected.
The WRI Demo Editor does not recommend using global variables inside the Manipulate section.
I will explain the problem with simple examples and I hope that the expert can know about it. I currently have something like this that works:
Manipulate[ p@x = 0; (*I'd like to use here *) p@y = 99; (*etc...*) foo, {{foo, 0, "foo"}, 0, 10, 1}, Initialization :> { p[x] = 99; (*my data live here *) p[y] = 0; (*my data live here *) } ]
But in the above, p [x] and p [y] are global. I tried managing Nothing, but this does not work:
Manipulate[ p[x] = 0; foo, {{foo, 0, "foo"}, 0, 10, 1}, {{p[x], 99}, None} (* syntax error, what is the correct syntax? *) ]
I cannot put a module around Manipulate to use it to save state. Is not allowed.
So, I need a way for these indexed objects to maintain state between each Manipulate update, like a control variable, but not global.
But the problem is I do not know how to do this. The only way I knew this was to use the Control No. trick
I know that Manipulate is basically a DynamicModule[] . This is why its own variables (control variables) keep state. I need these indexed objects to look like them. Can I use DynamicModule [] inside Manipulate to do this or is there a simple solution for this?
Btw, I found that I can do the following
Manipulate[ z, {{foo, 0, "foo"}, 0, 10, 1}, {{z, p[x]}, None} ]

But I'm not sure what to do with the above. I need to use p @x, not z.
The strange thing is, you can define an array of indexed objects, but not one?
Manipulate[ z, {{foo, 0, "foo"}, 0, 10, 1}, {{z, Table[p[i], {i, 5}]}, None} ]

Thanks for any tips.
Update:
I cannot answer Mike below to work as I needed. For example, suppose I want p [x] to initialize to 0, and then in every Manipulate update I want to add it to it. How to do it? This is what I tried:
Manipulate[ DynamicModule[{p, x}, (*not working *) p@x = p@x + 1; p@x , Initialization :> { p@x = 0; } ], {{n, 0, "n"}, 0, 10, 1}, TrackedSymbols :> n ]
Will continue to try ...
Update 2:30 AM
The following is a clearer example of the problem in case the above is not clear.
Manipulate[ p@x = p@x + 1;(*I'd like to use here*) n; Row[{" p@x =", p@x }], Button["click to update p@x ", n++], {{n, 0}, None}, TrackedSymbols :> {n}, Initialization :> { p@x = 0; } ]

In this example, the indexed object p [x] is a global variable, so its state is preserved. I need to do the same, but without p [x] defined as global, but move it as part of the Manipulation so that it becomes localized, but also retains its state.
The problem again is that the control None syntax does not allow me to type
{{ p@x ,0},None}
I hope this example simplifies the situation.