Counter


Node Information
Counts from zero and adds 1 each time value is requested.
General Information
• This node doesn't have other available options.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Reset IN RUN MULTIPLE FALSE FALSE
Value OUT Int32 MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Utilities
{
    [IsNode("Counter")]
    public class Counter : Node
    {
        Port reset = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Reset");
        Port val = new Port(PortType.OUT, typeof(int), AcceptsLinks.MULTIPLE, "Value");
        Variable Var1 = new Variable("int", "", "0");
        public Counter()
        {
            this.Name = "Counter";
            NodeType = KGraph.NodeType.Function;
            ReturnType = typeof(int);
            AddPort(reset);
            AddPort(val);
            Variables.Add(Var1);
            reset.Instructions = "init";
            Information = "Counts from zero and adds 1 each time value is requested.";
        }
        public override string Code()
        {
            Var1.Name = reset.ID;
            reset.Instructions = Var1.Name + "= 0;";
            string code = Var1.Name + "++; return " + Var1.Name + ";";
            return code;
        }
    }
}