+5
Completed

Dictionaries

James A 3 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 7

Would you be able give an example of how to use dictionaries? I'm trying to figure out how to store keys and values but i keep getting type: (null). Apologies if i am missing something super basic :P Thanks in advance :D

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):

Hey james, i have same problem to with  dictionaries, so i solve with make one class and inherit from System.Collections.Generic.Dictionary  and update all unit.

Shouldn't be a problem, and not necessary to do this. Only reason is if you are actually trying to make your own type that can only intereact with object and your type. Or maybe some other weird/not weird reasons. Here is an example of a working dictionary, setting and getting it. Nothing null coming back for me, here.


A little more information. What may be happening is you are not caching the newly created dictionary in a cache or variable. The create Dictionary item, will create a brand new one every time its output is used. If it were on a control output, which it isn't... you could be guaranteed the result will be cached in it's output. Since it is not, it doesn't create a reference. It only creates a new one.wherever you attach it to. Like this example, iterating through numbers and adding keys, would not work trying to get a previous iterated variable.You will only ever have a dictionary with one key and value. Many different dictionaries with one key actually. None are cached though, so you will never get the proper value you are looking for.


Pending Review

There is a missing node for dictionary enumeration at the moment, because foreach enumeration on the dictionary interface does not work like normal foreaches. I'll see if I can add it in for the next version.

+1
Answered

Added a Dictionary toggle to the foreach loop for the next version: