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?
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.
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:
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).
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
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.
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
}
}
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:
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:
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
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:
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.