|
Sum structure valuesHi, I have the following structure: 0 0= "content": 1 1= "name": shares 1 0= "content": 2 1= "name": shares 3 0= "content": 0 1= "name": shares 4 0 = "content": 1 1= "name": shares How can I sum the values in content so I get 4 as a result?
|
To my knowledge this is only possible with JavaScript (native in QC) or LUA Script (http://docs.boinxtv.com/lua_patch).
I found this comp. on my computer... I don't remember who is the author. I think it's what you are looking for.
Thanks, and sorry for my poor text formatting. I think i'd better upload a picture.
I can't get your comp to sum the values of "shares" item. How can I do that?
Note that not all members contain that item and that that item could be any number, not just 1.
@Sala28: Interesting: I didn't know that an Iterator can have an output, thought.
@pho: You have to put a "Structure Key Member" patch (with key "content") between "Structure Index Member" and "+" patch to get your "content"-value.
Thanks, it works perfectly. I need to look into iterators better.
BTW, do you know how to sort the structure in descending order by the "shares" number?
Use the structure sort patch and put an expression mark in front of the value for sorting descriptor. ie: !shares
the sorting is wrong. It is sorting by the first digit only, then by the first two and so on.
this is what I get: