NodeCanvas Forums › Support › Blackboard Variable Types issue › Reply To: Blackboard Variable Types issue
Hey,
Sure 🙂
Bellow are the 2 Dictionary related actions you requested. Notice that both of these actions are able to work with any type of value, but only string for key. Since only one generic argument is supported in NodeCanvas at the moment, I chosen it to be string, since it is the most commonly used one of course 🙂
Both can be found under category “Blackboard/Dictionaries”. Like the rest of the generic tasks, you simply have to choose integer for your case like for example “Blackboard/Dictionaries/AddElementToDictionary (T)/AddElementToDictionary(Integer)”.
Let me know if these work for you.
AddElementToDictionary.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
using UnityEngine; using System.Collections.Generic; using ParadoxNotion.Design; using NodeCanvas.Framework; namespace NodeCanvas.Tasks.Actions{ [Category("✫ Blackboard/Dictionaries")] public class AddElementToDictionary<T> : ActionTask { [BlackboardOnly] [RequiredField] public BBParameter<Dictionary<string, T>> dictionary; public BBParameter<string> key; public BBParameter<T> value; protected override string info{ get {return string.Format("{0}[{1}] = {2}", dictionary, key, value);} } protected override void OnExecute(){ dictionary.value[key.value] = value.value; EndAction(); } } } |
GetDictionaryElement.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
using UnityEngine; using System.Collections.Generic; using ParadoxNotion.Design; using NodeCanvas.Framework; namespace NodeCanvas.Tasks.Actions{ [Category("✫ Blackboard/Dictionaries")] public class GetDictionaryElement<T> : ActionTask { [BlackboardOnly] [RequiredField] public BBParameter<Dictionary<string, T>> dictionary; public BBParameter<string> key; [BlackboardOnly] public BBParameter<T> saveAs; protected override string info{ get {return string.Format("{0} = {1}[{2}]", saveAs, dictionary, key);} } protected override void OnExecute(){ saveAs.value = dictionary.value[key.value]; EndAction(); } } } |
Join us on Discord: https://discord.gg/97q2Rjh