Home AMX User Forum NetLinx Studio

Combine Button Events?

I have a number of Button Events that run the same code.

Currently I have them listed as:
BUTTON_EVENT[dvTP1,801]
BUTTON_EVENT[dvTP1,802]
BUTTON_EVENT[dvTP1,803]
BUTTON_EVENT[dvTP1,804]
BUTTON_EVENT[dvTP1,805]
BUTTON_EVENT[dvTP1,806]
BUTTON_EVENT[dvTP1,807]
BUTTON_EVENT[dvTP1,808]
BUTTON_EVENT[dvTP1,809]
BUTTON_EVENT[dvTP1,810]
{
  //Do Script
}

Is there a way to combine all those button events or do a range?

Thanks

Comments

  • mpullinmpullin Posts: 949
    The way I always do this is define an array of integers and include it instead of a channel number in the BUTTON_EVENT, e.g.
    DEFINE_CONSTANT
    VOLATILE INTEGER btnABUTTONRANGE[] = {801, 802, 803, 804};
    
    DEFINE_EVENT
    BUTTON_EVENT[dvTP,btnABUTTONRANGE]{
      PUSH:{
        doScript(GET_LAST(btnABUTTONRANGE));
      }
    }
    
    This will call the function doScript with the parameter 2 in the case of button 802 being pushed.
  • jabramsonjabramson Posts: 106
    Perfect, thanks
  • PhreaKPhreaK Posts: 966
    You can also use a devchan array. This will allow you to utilize a single handler for events from multiple devices as well as channels.
    ...
    
    define_variable
    
    devchan combinedControl = {
    	{dev1, 1},
    	{dev1, 2},
    	{dev2, 1}
    }
    
    
    define_event
    
    button_event[combinedControl] {
    
    	push: {
    		// do stuff here
    	}
    
    }
    
    ...
    
Sign In or Register to comment.