Hi, could someone post an example of the ‘ToDictionary (Spreads )’ node works in VL?
hei guest, please note that the dictionary in VL is momentarily half-broken due to an error in .net. the error is being tracked here: https://github.com/dotnet/coreclr/issues/2191 and here: https://github.com/dotnet/corefx/issues/4726
in the meantime here is the official c# documentation on ToDictionary that you can consult for a general understanding: https://msdn.microsoft.com/en-us/library/bb549277(v=vs.110).aspx
Thanks Joreg,
That does explain why I was getting errors, and it seems I was using the Node Correctly. For now I’m accumulating the dictionary by putting add(dictionary) in a loop, and using try get to retrieve the entries.
Just a note to say that despite the occasional errors and the change in thinking (I still struggle to get my head around delegates) I’m enjoying using VL. Its a very elegent language that does well to limit the quirks of dotnet for a non-coder like myself. And while I’m getting used to its implementation and figuring its strengths and weaknesses for my approach to vvvv, I’m beginning to appreciate the freedoms it allows.
Thanks to all the devs,
HNY
add and tryget is the way to go indeed. good to hear you’re enjoying it!
Since the upstream issue (https://github.com/dotnet/corefx/issues/4726) is fixed the dictionary nodes of VL should work again in latest alpha.
Thanks, seems to be working okay.
Any chance of an example of constructing and reading/writing to a dictionary?
something like that?
DictBasics.zip (3.5 KB)
DictBasics0.1.zip (6.5 KB)
Whats with the red links when I try and make my own?
Also right click with a tablet, is mostly not working when clicking in boolean ioboxes in VL (along with left clicking), I hear you, dont use a tablet…
And if I wanted to create a saved dictionary that I loaded on open, how would that work?
Having seen Dottore’s post I’m guessing you’ve been talking about things I’m interested in, ie loading/saving presets, is a dictionary even the way to do that?
hi cat, a very helpful feature of VL is the error messages. if you hover over an element with error the tooltip gives you information about the problem. here the message on the link says: “Feeding data into the same sink multiple times in the same operation is not possible”. so basically Dict2 is data field where you can read and write. but you write two times on “Update”, the Empty and the new result after the If region. this also explains why both links are red, you need to move one of the two writes to another operation.
what you need to do is assign the Empty node to ‘Create’ (white), same as the other one that i posted. in order to do that right click the Empty node or the link and click Assign → Create. so when create is executed (when the node that is defined by the patch gets created) you store an empty dictionary to Dict2. then on ‘Update’ (gray) you modify the data from Dict2 and store it back to the same place.
highly depends on how the data you want to store is structured. starting with a dictionary is not wrong at all. to load/save data, have a look at the serialize and deserialize nodes. they can store your dictionary to disc, but can also serialize your own types created with VL.
Ok thanks, I saw the error message just didn’t know what it referred to…
Had to rewire the Dict2 to the add, via a diamond thing, but now I have a stray wire connected to nothing, is this bug or feature? Can’t delete it, if I click on it just get another point.
also my presets consist of pin address, value, fade time, fade type. Dictionary only takes one value per key?
So I could format it as I do in vvvv, new line per field, many pins in one preset. I’ve been using the table nodes for this, but theyre quite slow, so I’m looking for a faster method.
Separate doesnt exist in VL I’m guessing I use split instead? (that would be another tagged node you need update in VL) How do I split on new line?
Should I instead use xml?
What will be the fastest method?
latest alphas already have Split (Strings) tagged as “separate” and there is also a “SplitToLines” node already.
This sounds to me like your KontrolPreset would make a fine vl specimen on its own. Changing a field from single-value to a spread would be a breeze (once you need them), and you consistently retain the power of typed and named pins across your vl patch (and beyond) which might make your whole approach more maintainable, then a dictionary (where you have to remember keynames).
yea, make a type called Preset that has all those properties. then you can even have spreads of presets… if you make your own type you can save it with the serialization nodes and get a ready made type out of it when you deserialize. no need for any string operation, let the computer do that for you.
also please revisit:
girlpower\VL\_Basics\DataStructure
for a basic example of what you’re likely looking for. and just to clarify: a dictionary can be used for saving your stuff but is not necessary. a dictionary is used in cases where you need key-value pairs. this might be the case in your example or not. when it comes to de/serialization in vl you can either use auto de/serialization as shown in the example above or create your own file-format by e.g. using xml-nodes as you suggested.
there is no right or wrong way of doing this, just different ways depending on your needs.
The idea for using a dictionary was so I can retrieve a preset by name quickly, I’ve tried table as mentioned and also from txt and xml files per preset, but I was missing presets occasionally using non blocking reads, and blocking reads, well block, so I’m looking for a way to keep everything in memory, but access individual presets quickly with minimum cpu. How would I select a specific preset from a data structure without using a dictionary? For example patch1preset15 when there maybe not be any other patch1 presets, or they’re could be a hundred.
I’ll be honest this is probably a blind alley I’m going down anyway as the last time I tried, merely getting the data into VL was a cpu hole anyway, a spread of several thousand strings, wasn’t good, which means I end up having to try and do everything in VL including zeroMq…
if that is your use-case, then exactly using a Dictionary. i just wanted to clarify that Dictionaries are not per-se a means for storing things on disk!
just a little update…latest alphas now come with a Dictionary example:
girlpower\_Basics\Dictionary
and the above mentioned DataStructure example has some more info on Saving/Loading data.