How can know which input has changed value?

unhandled

(Andrealu2012) #1

i have 2 inputs,hoping to change one of them,then output show,which one has changed
i code as follow but failed,could someone explain it,Thank you!

      string s = "";

    protected override void SolveInstance(IGH_DataAccess DA)
    {
        int AInput = Params.IndexOfInputParam("A");
        int BInput = Params.IndexOfInputParam("B");

        Params.Input[AInput].ObjectChanged += showAMessage;
        Params.Input[BInput].ObjectChanged += showBMessage;

        DA.SetData("print", s);
    }
    public void showAMessage(object source, EventArgs e)
    {
        s = "A changes";
    }
    public void showBMessage(object source, EventArgs e)
    {
        s = "B changes";
    }

image


#2

Try something like this:

protected override void SolveInstance(IGH_DataAccess DA)
    {
        string s = "";

        int AInputValue = 0; 
        DA.GetData(0, ref AInputValue);

        int BInputValue = 0;
        DA.GetData(1, ref BInputValue);

        if (AInputValue != m_Ainput_remember)
        {
             s = "A was modified";
        }

        if (BInputValue != m_Binput_remember)
        {
             s = "B was modified";
        }

        // Now, store ("remember") last value until checking next time
        m_Ainput_remember = AInput;
        m_Binput_remember = BInput;

        DA.SetData("print", s);
    }
// < additional code>

private int m_Ainput_remember;
private int m_Ninput_remember;

// Rolf


(Andrealu2012) #3

RIL,i tried your method,it is almost ok,but remains one problem:
if i drag the slide ,the output can show the result string,but when mouseUp,the output become “empty”…


this is code:

    protected override void SolveInstance(IGH_DataAccess DA)
    {
        string s = "";

        double A =0, B=0;
        DA.GetData("A", ref A);
        DA.GetData("B", ref B);

        if (A != m_Ainput_remember)
        {
            s = "A was modified";
        }

        if (B != m_Binput_remember)
        {
            s = "B was modified";
        }
        m_Ainput_remember = A;
        m_Binput_remember = B;
   
        DA.SetData("print", s);
    }

this is the MatrixToolbox.gha (26.5 KB)
there is some component in MatrixToolbox,and the component of this question is in this place:
image
Thank you!