Questions about handling persistent data in panels
-
So I have a bit of data that I need to keep persistent so it loads every time without the user having to save a preset.
Most of it is in multi-dimensional arrays.
I have been using the panel.setValue() and panel.getValue() to handle this data,
but the Docs say this:"It's heavily recommended that this will be just a simple number, but you can choose to use more complex types if your widget that demands that (we'll cover this case in a example later on). But even then it might be more efficient to store the actual value as an array in the data object and use the Control Value as index:"
// Not very efficient this.data.setValue("First Item"); // Better, as it doesn't need to create the string each time this.data.values = ["First Item", "Second Item", "Third Item"]; this.data.setValue(0);
So...
- I don't understand why anything other than a single number value is discouraged.
- I don't understand the example above, as I don't see where it is even comparing the methods as the first method is "this.data.setValue()" which is not either method? Seems to be a hybrid of the two ("UI" data and "Control" data)?
Underneath that I see so clear way the two lines are related. How is "this.data.setValue(0)" acting on the previous line?
It seems that somehow the suggestion is to store data some data as "Control" data then have it populate analogs of that data on the panel.data by putting an inline function on the "OnControl" callback.
There is later an example using the ButtonPack doing this sort of thing, but I have to ask what is the utility of having to get and set the data from the panel.setValue() and panel.getValue() versions to their panel.data versions? Wouldn't it be easier to just store the data directly using the setValue() method and retrieve using the getValue() method, using less code and having less redundancy? It seems like it would be less efficient to have to store data to 2 separate places every time you are recording/editing data that is to be persistent.
-
@VirtualVirgin said in Questions about handling persistent data in panels:
But even then it might be more efficient...
I think the word here is efficiency, so it's not discouraged as I understand it. I use object stored in panel's value for a very long time and I'm sure many of us are doing so.
The example looks erroneous, it should probably be:
this.data.values = ["First Item", "Second Item", "Third Item"]; Panel.setValue(this.data.values[0]); // <- so not in the data object
But, since the
data
object isn't persistent, it would make even more sense to hard script the values:const var values = ["First Item", "Second Item", "Third Item"]; // script the array if the project allows for it... Panel.setValue(values[0]); // <- so not in the data object
But, as I said at first, storing an object directly to the
value
works on is own (even with a bit of efficiency drawback) so if this is what you need, you can go for it -
@ustk
Thank you very much for that response!I have been planning on more data storage using the panel.setValue() method and wanted make sure I'm not shooting myself in the foot with it, so after reading that section in the Docs (probably for the 5th or 6th time now) I was just getting confused.
It's great to get some help and be able to move past a sticking point :)
Much appreciated.