Object arguments being passed to all objects of the same type


    Nov 12 2011 | 12:31 am
    Hi,
    I've just made a pretty simple external and noticed that if I have more than one in the same patch, they all take on the attributes specified by the object arguments within the last one I create. I've made a few externals in the past and to my knowledge never had this problem, although as far as I can remember this is the first one I have made that accepts arguments.
    I have uploaded the .c file below
    Any advice would be much appreciated.
    Benny

    • Nov 12 2011 | 10:27 am
      You have declared all your variables as globals, so of course they will be shared between ALL instances of your class. To achieve what you want you need to put your variables inside the object struct. That way their scope will be local to each instance of your class.
      ////////////////////////// object struct
      typedef struct _latch
      {
      	t_object           ob; // the object itself (must be first)
      
      	void*                latch_output;	//creates an outlet
      
              // variable declarations
              int                    i_outputValue;
              int                    i_comparisonValue;
              int                    i_incomingInt;
              int                    i_latchRange;
      
      } t_latch;
      Cheers.
      - Luigi
    • Nov 12 2011 | 12:47 pm
      Thank you Luigi,
      Seems obvious now, I'm new-ish to all this coding etc... so that is a valuable lesson learned.
      Thank you again
      Benny