Nodes for Dictionaries

FlowCanvas Forums Support Nodes for Dictionaries

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1052
    chocolacode
    Participant

    Hey,

    I am trying to get some nodes in FC for Dictionaries. Some time ago, I asked you a favor to get couple of Tasks in NC for Dictinaries, and you really helped me 🙂

    Now I am trying to create the same 2 nodes, “Add entries” and “Get entries by providing a key”. But I am stuck with this, I am trying but getting syntax errors,

    can you please help me creating these 2 nodes? Based on those I will try to create more, like iterate, or sort, etc.

    —–I am using a short code example to create the variable in the Balckboard… as you provided.(This works perfect!!)

    using UnityEngine;
    using System.Collections.Generic;
    using NodeCanvas.Framework;

    public class myDictionariesExample : MonoBehaviour {

    [ContextMenu(“AddDictionaryVariable”)]
    void AddDictionaryVariable(){
    var bb = GetComponent<Blackboard>();
    bb.AddVariable(“Enemies”, typeof(Dictionary<string, GameObject>));
    }
    }

    —–And this is the code that I am trying to create the “Add entries” node, but no working 🙁
    //Dictionaries
    [Category(“Functions/Dictionaries”)]
    public class AddDictionaryItem : CallableFunctionNode<Dictionary<string, T>{
    public override Invoke(IDictionary<string, T> dictionary, string key, object item){
    dictionary.Add(key, item);
    return dictionary;
    }
    }

    Thanks in advance!!

    #1058
    Gavalakis
    Keymaster

    Hey,

    Here you go 🙂

    Please note that these work with IDictionary. If you want, you can change these to work with Dictionary instead (except the ClearDictionary, which is best to work with IDictionary to avoid yet another generic node).

    Let me know if these work for you.
    Cheers!

    Join us on Discord: https://discord.gg/97q2Rjh

    #1062
    chocolacode
    Participant

    That is Great!!

    this will give me a good start with Dictionaries

    thanks so much for your help!!! 🙂

    #1063
    chocolacode
    Participant

    Hey Gavalakis,

    I started using these new nodes and they worked well, except the “Remove” one, which I was expecting to get a boolean value as a return value, however I am receiving the Dictionary itself

    Also I tried to create myself the “ContainsKey” node but I can not make it to work(In this one I am also expecting to have the return value as Boolean)

    Could you please help me? 🙂

    Thanks in advance!!

    see my screens below

    Dictionaries-nodes-boolean

    Dictionaries-nodes-boolean2

    Attachments:
    You must be logged in to view attached files.
    #1066
    chocolacode
    Participant

    Hi there,

    I am also trying to create a node for “Get Value” from Dictionary and also got stuck there

    Can you please also help me with such node?

    Thanks in advance!

    #1067
    Gavalakis
    Keymaster

    Hey,

    Here are the nodes you asked for.
    Both ContainsKey and GetElement can be substituted with TryGetValue though, which does both in one go. 🙂

    Cheers!

    Join us on Discord: https://discord.gg/97q2Rjh

    #1070
    chocolacode
    Participant

    Thank you!!!

    #1071
    Gavalakis
    Keymaster

    You are very welcome! 🙂

    Join us on Discord: https://discord.gg/97q2Rjh

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.