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
Thanks
Comments
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.
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
BUTTON_EVENT[dvTP,nSomeButtons] { PUSH: { nIDX = get_last(nSomeButtons); nAudio = layout[nIDX][1]; nVideo = layout[nIDX][2]; nRGB = layout[nIDX][3]; } };Errr... why don't you just try it and find out?
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.
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.
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 } }