Find and share HowTos to various installations / configurations!
7 posts • Page 1 of 1
7 posts
• Page 1 of 1
Nikolay
Posts:34
Joined: Tue Aug 21, 2012 7:10 am
Array in Para
Postby Nikolay »
Dear colleagues.
Tell me, please, how to work with elements of an array of type dyn_XXX. Suppose I created an array of integers in Para and now I want to get the value of the first and last elements of this array from the ctrl script. Next, let's say I need to insert a random value into the third one in this array. How can I do it?
Thank you in advance.
To get the array:
dyn_int di;
dpGet("your.dpe", di);
Access first: DebugN(di[1]);
Access last: DebugN(di[dynlen(di)]);
Set third in array: di[3] = 12345;
Put back on DPE: dpSet("your.dpe", di);
This is understandable, so we are doing now. We want to get rid of the extra variable, do not shift the array from Para to the ctrl array of the script. Can I directly interact with the dpGet and dpSet functions with an array from Para.
I would like something like this:
int var;
dpGet ("test.dddd [3]", var);
dpSet ("test.dddd [5]", var);
Para is nothing more than a panel, using the CTRL scripting language. What you see in the Para panel is what was received by using dpGet().
And no, you can not dpGet() just one element out of the whole array.
What you could do, if that makes sense in your application, is to create a different kind of datapoint type, using the array type, where every value
is stored inside a different DP-Element. With that you then can read/write a single value.
Well, thanks. Then such question, how you recommend to organize a stack? We need to get access to the stack from different ctrl scripts, so we decided to use Para as a data store. Any idea how to implement this?
Let me give you a warning. It is never a good idea to access one datapoint from several control managers at the same time. Script 1 may be doing a dpGet() followed by a dpSet(). But just betewen de dpGet() and the dpSet() another script may have changed your datapoint.
I would advise 2 solutions:
a) I would implement one script manager to act as a 'stack manager'. This script has its own datapoint with elements called 'AddItem' or 'RemoveItem'. N scripts can send commands to this script manager but there is only one script that actually changes your array in the datapoint. Note that the callbacks in this script manager will be synchronized. The script will finish a callback before accepting a new one.
b) (This is my least favorite) You can actually lock a datapoint. Script a could lock it before doing the dpGet() and dpSet(). This guarantees that only one script at a time can modify the array.
if your update interval is low, then I would prefer (a). When your update is high then I would do (b)