Home AMX User Forum NetLinx Studio

get_last and multi-dimensional array

Can anyone tell me if get_last works with multi-dimensional arrays? If so what index does it return and should you use an array to store what is returned?


Thanks

Comments

  • Joe HebertJoe Hebert Posts: 2,159
    Can you give us an example of what you are trying to accomplish? GET_LAST() only works with BUTTON_EVENTs and CHANNEL_EVENTs.
  • DHawthorneDHawthorne Posts: 4,584
    I've never felt the need to go multi-dimensional in a button array in an event handler, but if it's consistent with the way arrays are handled elsewhere, it will reflect the top level. YOu are going to have to play with it to be sure.
  • KailexKailex Posts: 5
    This might be a bad example but if I were to define routes for a particular button_event take the following as an example

    4 preset buttons and 3 switchers (audio, video, rgb)

    DVD = in 1 audio, in 1 on video, not connected on rgb switch
    VCR = in 2 audio, in 2 on video, not connected on rgb switch
    PC = in 3 audio, in not connected on video, 5 on rgb switch
    AUX = in 4 audio, not connected on video, 8 on rgb switch


    I'd like to use a multi-dimensional array to setup the routes as follows:
    myrouting[4][4] =
    {
         {201, 1, 1, 0},   //DVD
         {202, 2, 2, 0},    //VCR
         {203, 3, 0, 5},   //PC
         {204, 4, 0, 8},   //LAPTOP
    
    }
    

    Does get_last return first index (row) the second index (column) or both indexes (an array of values, row and column)?

    In the above example if I press the DVD preset button (201) and use get_last(myrouting) what is returned.

    1 or {1, 1}

    Thanks for the assistance.
  • Joe HebertJoe Hebert Posts: 2,159
    I don?t see how GET_LAST() can work with a multi-dimensional array since a button array or channel array in an event handler can only be one dimensional and GET_LAST() only works with BUTTON_EVENTs and CHANNEL_EVENTs.

    How is your BUTTON_EVENT defined? You can?t do something like:

    BUTTON_EVENT[dvTP,myrouting]

    Also GET_LAST() will only return one number, it will never return something like (1,1).

    Here?s a quick example of how GET_LAST() works:
    DEFINE_DEVICE
    
    dvTP = 10001:1:0
    
    DEFINE_CONSTANT
    
    INTEGER nSomeButtons[] = {201,202,203,204}
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvTP,nSomeButtons] {
    
       PUSH: {
          SEND_STRING 0, "'GET_LAST() index = ',ITOA(GET_LAST(nSomeButtons))"
       }
    }
    

    And here is the output when you push 201,202,203 and then 204:

    Line 1 :: GET_LAST() index = 1 - 15:35:17
    Line 2 :: GET_LAST() index = 2 - 15:35:20
    Line 3 :: GET_LAST() index = 3 - 15:35:23
    Line 4 :: GET_LAST() index = 4 - 15:35:26

    HTH
  • GSLogicGSLogic Posts: 562
    once you have the get_last() number, you can use it to reference other arrays (multi-d or structures) which hold your info.
    BUTTON_EVENT[dvTP,nSomeButtons] 
    {
        PUSH: 
        {
           nIDX   = get_last(nSomeButtons);
           nAudio = layout[nIDX][1];
           nVideo = layout[nIDX][2];
           nRGB   = layout[nIDX][3];
        }
    };
    
  • Kailex wrote:
    Does get_last return first index (row) the second index (column) or both indexes (an array of values, row and column)?

    Errr... why don't you just try it and find out?
  • KailexKailex Posts: 5
    I've been testing get_last against a multi-dimensional array but it always gives me a syntax error, so I'm assuming it doesn't work with multi-dimensional.

    However, I think I can use the index from get_last from a single dimensional array to get what I need from a separate multi-dimensional array that contains routing or whatever.

    example:
    mybuttons[] =
    {
         201,     //DVD
         202,     //VCR
         203,     //PC
    }
    
    myrouting[][]=
    {
         {1, 1, 0},     //DVD
         {2, 2, 0},     //VCR
         {3, 0, 5}      //PC
    }
    
    BUTTON_EVENT[dvSomeDevice, mybuttons]
    {
         btn = get_last(mybuttons)
    
    
         switch (mybuttons[btn])
         {
    
              case 201:
              {
                   routeaudio(myrouting[btn][1])   //a function to route the audio
                   routevideo(myrouting[btn][2])   //a function to route the video
                   routergb(myrouting[btn][3])      //a function to route the rgb
                   
              }
    
             //**********  ETC.
    
         }
    }
    
    
    

    I'm sure there's probably an easier way, but this has answered my question.

    Thanks for the help.
  • Joe HebertJoe Hebert Posts: 2,159
    Kailex wrote:
    I'm sure there's probably an easier way, but this has answered my question.

    Thanks for the help.
    Sure thing.

    Scroll up to post #6 by GSLogic. It?ll get you closer to where you want to go. You should be able to dump the SWITCH CASE stuff.
  • AMXJeffAMXJeff Posts: 450
    Stuff

    You are kind of defeating the purpose of GET_LAST.
    // your way
    BUTTON_EVENT[dvSomeDevice, mybuttons]
    {
         btn = get_last(mybuttons)
    
    
         switch (mybuttons[btn])
         {
    
              case 201:
              {
                   routeaudio(myrouting[btn][1])   //a function to route the audio
                   routevideo(myrouting[btn][2])   //a function to route the video
                   routergb(myrouting[btn][3])      //a function to route the rgb
                   
              }
    
             //**********  ETC.
    
         }
    }
    
    // prefered way #1 - CODE NOT Relying on button numbers at all. More Protable.
    BUTTON_EVENT[dvSomeDevice, mybuttons]
    {
    	PUSH:
    	{
    		btn = GET_LAST(mybuttons);
    	
    		switch (btn)
    		{
    			case 1:
    			{
    					 routeaudio(myrouting[btn][1])   //a function to route the audio
    					 routevideo(myrouting[btn][2])   //a function to route the video
    					 routergb(myrouting[btn][3])      //a function to route the rgb
    					 
    			}
    		
    			 //**********  ETC.
    		
    		}
    	}
    }
    
    // prefered way #2 - DO YOU REALLY NEED A SWITCH CASE?
    BUTTON_EVENT[dvSomeDevice, mybuttons]
    {
    	PUSH:
    	{
    		btn = GET_LAST(mybuttons);
    	
    		routeaudio(myrouting[btn][1])   //a function to route the audio
    		routevideo(myrouting[btn][2])   //a function to route the video
    		routergb(myrouting[btn][3])      //a function to route the rgb
    	}
    }
    
Sign In or Register to comment.